├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── babel.config.js ├── banner.png ├── jest.config.js ├── package-lock.json ├── package.json ├── preset ├── browser │ ├── jest-preset.js │ ├── resolver.js │ └── transform.js ├── node │ ├── jest-preset.js │ └── transform.js └── shared.js └── test ├── browser.test.jsx └── server.test.jsx /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "arrowParens": "avoid", 7 | "printWidth": 100 8 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ryan Carniato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Solid Jest 3 |

4 | 5 | # Solid Jest 6 | 7 | This library contains presets for SolidJS to easily get started testing with Jest for both browser and server rendering with Node. 8 | 9 | ### Usage 10 | 11 | In your jest.config.js 12 | 13 | ```js 14 | module.exports = { 15 | preset: "solid-jest/preset/browser" 16 | }; 17 | ``` 18 | 19 | ```js 20 | module.exports = { 21 | preset: "solid-jest/preset/node" 22 | }; 23 | ``` 24 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | test: { 4 | presets: [ 5 | [ 6 | "@babel/preset-env", 7 | { 8 | "targets": { 9 | "node": "current" 10 | } 11 | } 12 | ] 13 | ] 14 | } 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solidjs/solid-jest/bac75127e9f29f42443b39a0c3b5128334e84f09/banner.png -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | projects: [ 3 | { 4 | preset: "./preset/node/jest-preset.js", 5 | displayName: "node", 6 | testEnvironment: "node", 7 | testMatch: ["/test/server.test.jsx"] 8 | }, 9 | { 10 | preset: "./preset/browser/jest-preset.js", 11 | displayName: "browser", 12 | testMatch: ["/test/browser.test.jsx"] 13 | } 14 | ] 15 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solid-jest", 3 | "version": "0.2.0", 4 | "description": "Jest presets for SolidJS", 5 | "author": "Ryan Carniato ", 6 | "homepage": "https://github.com/solidjs/solid-jest#readme", 7 | "license": "MIT", 8 | "files": [ 9 | "preset" 10 | ], 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/solidjs/solid-jest.git" 14 | }, 15 | "scripts": { 16 | "test": "jest" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/solidjs/solid/issues" 20 | }, 21 | "devDependencies": { 22 | "babel-preset-solid": "^1.0.0", 23 | "jest": "^27.0.0", 24 | "solid-js": "^1.0.0" 25 | }, 26 | "peerDependencies": { 27 | "babel-preset-solid": "^1.0.0" 28 | }, 29 | "dependencies": { 30 | "@babel/preset-env": "^7.13.9", 31 | "babel-jest": "^27.0.0", 32 | "enhanced-resolve-jest": "^1.1.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /preset/browser/jest-preset.js: -------------------------------------------------------------------------------- 1 | const shared = require("../shared"); 2 | 3 | module.exports = { 4 | ...shared, 5 | // uses a webpack style resolver, the default one has many issues. 6 | resolver: require.resolve("./resolver"), 7 | testEnvironment: 'jsdom', 8 | transform: { 9 | "\\.[jt]sx$": require.resolve("./transform"), 10 | ...shared.transform 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /preset/browser/resolver.js: -------------------------------------------------------------------------------- 1 | const { create, getDefaultConfig } = require("enhanced-resolve-jest"); 2 | 3 | module.exports = create(jestConfig => { 4 | const baseConfig = getDefaultConfig(jestConfig); 5 | baseConfig.aliasFields = ["browser"]; 6 | baseConfig.mainFields = ["browser", "main"]; 7 | return baseConfig; 8 | }) -------------------------------------------------------------------------------- /preset/browser/transform.js: -------------------------------------------------------------------------------- 1 | const babelJest = require("babel-jest"); 2 | 3 | module.exports = babelJest.default.createTransformer({ 4 | presets: ["babel-preset-solid"] 5 | }) -------------------------------------------------------------------------------- /preset/node/jest-preset.js: -------------------------------------------------------------------------------- 1 | const shared = require("../shared"); 2 | 3 | module.exports = { 4 | ...shared, 5 | // avoid loading jsdom. 6 | testEnvironment: "node", 7 | transform: { 8 | "\\.[jt]sx$": require.resolve("./transform"), 9 | ...shared.transform 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /preset/node/transform.js: -------------------------------------------------------------------------------- 1 | const babelJest = require("babel-jest"); 2 | 3 | module.exports = babelJest.default.createTransformer({ 4 | presets: [ 5 | [ 6 | "babel-preset-solid", 7 | { 8 | generate: "ssr", 9 | hydratable: true 10 | } 11 | ] 12 | ] 13 | }) -------------------------------------------------------------------------------- /preset/shared.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: { "\\.[jt]s$": "babel-jest" }, 3 | transformIgnorePatterns: ["node_modules\/(?!solid-js.*|.*(?<=\.[tj]sx))$"] 4 | }; -------------------------------------------------------------------------------- /test/browser.test.jsx: -------------------------------------------------------------------------------- 1 | describe("Test the browser", () => { 2 | it("should render in the browser", () => { 3 | const d =
text content
; 4 | expect(d.textContent).toBe("text content"); 5 | }) 6 | }) -------------------------------------------------------------------------------- /test/server.test.jsx: -------------------------------------------------------------------------------- 1 | import { renderToString } from "solid-js/web" 2 | 3 | describe("Test the server", () => { 4 | it("should render in the server", () => { 5 | const d = renderToString(() =>
text content
); 6 | expect(d).toBe(`
text content
`); 7 | }) 8 | }) --------------------------------------------------------------------------------