Skip to content

Commit

Permalink
Use jest for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Jan 2, 2024
1 parent 5ca55c9 commit ffb5b8f
Show file tree
Hide file tree
Showing 15 changed files with 3,778 additions and 3,026 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
"@babel/preset-env",
"babel-preset-solid",
[
"@babel/preset-typescript",
{
"onlyRemoveTypeImports": true
}
]
]
}
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"plugins": ["@typescript-eslint", "no-only-tests", "eslint-comments"],
"ignorePatterns": ["node_modules", "dist"],
"parserOptions": {
"project": ["./tsconfig.json", "./tsconfig.node.json"],
"project": ["./tsconfig.json", "./tsconfig.node.json", "./test/tsconfig.json"],
"tsconfigRootDir": ".",
"sourceType": "module"
},
Expand Down
33 changes: 33 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @type {import('@jest/types').Config.InitialOptions} */
const common_config = {
/*
to support NodeNext module imports
https://stackoverflow.com/questions/73735202/typescript-jest-imports-with-js-extension-cause-error-cannot-find-module
*/
globals: {"ts-jest": {useESM: true}},
moduleNameMapper: {
"(.+)\\.js": "$1",
"(.+)\\.jsx": "$1",
},
extensionsToTreatAsEsm: [".ts", ".tsx"],
}

/** @type {import('@jest/types').Config.InitialOptions} */
const client_config = {
...common_config,
testEnvironment: "jsdom",
preset: "solid-jest/preset/browser",
testMatch: ["<rootDir>/test/**/*.test.(js|ts)?(x)"],
testPathIgnorePatterns: ["/node_modules/", "ssr"],
setupFilesAfterEnv: ["<rootDir>/test/waapi-polyfill.js"],
}

/** @type {import('@jest/types').Config.InitialOptions} */
const server_config = {
...common_config,
preset: "solid-jest/preset/node",
testMatch: ["<rootDir>/test/ssr.test.(js|ts)?(x)"],
}

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = process.env["SSR"] ? server_config : client_config
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"scripts": {
"prepublishOnly": "pnpm build",
"build": "tsup",
"test": "pnpm run test:client & pnpm run test:ssr",
"test:client": "vitest",
"test:ssr": "vitest --mode ssr",
"test": "pnpm run test:client && pnpm run test:ssr",
"test:client": "jest --config jest.config.cjs",
"test:ssr": "SSR=true jest --config jest.config.cjs",
"format": "prettier --cache -w .",
"lint": "pnpm run lint:code & pnpm run lint:types",
"lint:code": "eslint --ignore-path .gitignore --max-warnings 0 src/**/*.{js,ts,tsx,jsx}",
Expand Down Expand Up @@ -47,21 +47,27 @@
"csstype": "^3.1.0"
},
"devDependencies": {
"@babel/preset-env": "^7.23.7",
"@babel/preset-typescript": "^7.23.3",
"@jest/types": "^29.6.3",
"@solidjs/testing-library": "^0.8.5",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.6",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"babel-jest": "^29.7.0",
"babel-preset-solid": "^1.8.6",
"eslint": "^8.56.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"jsdom": "^23.0.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^3.1.1",
"solid-jest": "^0.2.0",
"solid-js": "^1.8.7",
"tsup": "^8.0.1",
"tsup-preset-solid": "^2.2.0",
"typescript": "^5.3.3",
"vite-plugin-solid": "^2.8.0",
"vitest": "^1.1.1"
"typescript": "^5.3.3"
},
"peerDependencies": {
"solid-js": "^1.8.0"
Expand Down
Loading

0 comments on commit ffb5b8f

Please sign in to comment.