Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Jan 3, 2024
1 parent f13cd87 commit 058edba
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 18 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

24 changes: 21 additions & 3 deletions jest.config.cjs → jest/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const transform_client_path = require.resolve("./transform-client.cjs")
const transform_ssr_path = require.resolve("./transform-ssr.cjs")
const resolver_path = require.resolve("./resolver.cjs")

/** @type {import('@jest/types').Config.InitialOptions} */
const common_config = {
rootDir: "../",
globals: {"ts-jest": {useESM: true}},
transformIgnorePatterns: ["node_modules/(?!solid-js.*|.*(?<=.[tj]sx))$"],
/*
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",
Expand All @@ -16,17 +22,29 @@ const common_config = {
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"],
/* uses a webpack style resolver, the default one has many issues. */
resolver: resolver_path,
/* transform ts and tsx files */
transform: {
"\\.[jt]sx$": transform_client_path,
"\\.[jt]s$": transform_client_path,
},
}

/** @type {import('@jest/types').Config.InitialOptions} */
const server_config = {
...common_config,
preset: "solid-jest/preset/node",
// avoid loading jsdom.
testEnvironment: "node",
testMatch: ["<rootDir>/test/ssr.test.(js|ts)?(x)"],
/* transform ts and tsx files */
transform: {
"\\.[jt]sx$": transform_ssr_path,
"\\.[jt]s$": transform_ssr_path,
},
}

/** @type {import('@jest/types').Config.InitialOptions} */
Expand Down
8 changes: 8 additions & 0 deletions jest/resolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {create, getDefaultConfig} = require("enhanced-resolve-jest")

module.exports = create(jestConfig => {
const baseConfig = getDefaultConfig(jestConfig)
baseConfig.aliasFields = ["browser"]
baseConfig.mainFields = ["browser", "main"]
return baseConfig
})
9 changes: 9 additions & 0 deletions jest/transform-client.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const babelJest = require("babel-jest")

module.exports = babelJest.default.createTransformer({
presets: [
"@babel/preset-env",
"babel-preset-solid",
["@babel/preset-typescript", {onlyRemoveTypeImports: true}],
],
})
15 changes: 15 additions & 0 deletions jest/transform-ssr.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const babelJest = require("babel-jest")

module.exports = babelJest.default.createTransformer({
presets: [
"@babel/preset-env",
[
"babel-preset-solid",
{
generate: "ssr",
hydratable: true,
},
],
["@babel/preset-typescript", {onlyRemoveTypeImports: true}],
],
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"prepublishOnly": "pnpm build",
"build": "tsup",
"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",
"test:client": "jest --config jest/jest.config.cjs",
"test:ssr": "SSR=true jest --config jest/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 @@ -57,6 +57,7 @@
"@typescript-eslint/parser": "^6.17.0",
"babel-jest": "^29.7.0",
"babel-preset-solid": "^1.8.6",
"enhanced-resolve-jest": "^1.1.0",
"eslint": "^8.56.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-no-only-tests": "^3.1.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"checkJs": true,
"types": ["node"]
},
"include": ["./tsup.config.ts", "./jest.config.cjs"]
"include": ["./tsup.config.ts", "jest"]
}

0 comments on commit 058edba

Please sign in to comment.