Skip to content

Commit

Permalink
feat: upgrade jest 29 (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
evenchange4 authored Jun 28, 2024
1 parent 655b84f commit c5e443f
Show file tree
Hide file tree
Showing 24 changed files with 1,259 additions and 994 deletions.
29 changes: 16 additions & 13 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ module.exports = {

bail: false,

globals: {
'ts-jest': {
tsconfig: {
jsx: 'react',
allowJs: true,
target: 'es6',
lib: ['esnext'],
module: 'commonjs',
moduleResolution: 'nodenext',
skipLibCheck: true,
esModuleInterop: true,
noUnusedLocals: false
transform: {
'^.+\\.[tj]sx?$': [
'ts-jest',
{
tsconfig: {
jsx: 'react',
allowJs: true,
target: 'es6',
lib: ['esnext'],
module: 'commonjs',
moduleResolution: 'nodenext',
skipLibCheck: true,
esModuleInterop: true,
noUnusedLocals: false
}
}
}
]
},

setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"devDependencies": {
"@types/cross-spawn": "6.0.1",
"@types/fs-extra": "^9.0.1",
"@types/jest": "^25.1.3",
"@types/jest": "^29.5.12",
"@types/node": "18.0.6",
"@types/puppeteer-core": "^5.4.0",
"@types/rimraf": "^3.0.0",
Expand All @@ -61,8 +61,8 @@
"got": "^10.7.0",
"husky": "^8.0.1",
"is-wsl": "^2.1.1",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"koa": "^2.13.1",
"lint-staged": "^10.1.2",
"lodash": "^4.17.15",
Expand All @@ -74,7 +74,7 @@
"rimraf": "^3.0.2",
"sass": "1.50.1",
"semver": "^7.3.2",
"ts-jest": "28.0.5",
"ts-jest": "^29.1.5",
"typedoc": "^0.23.0",
"typedoc-plugin-markdown": "^3.12.1",
"typedoc-plugin-missing-exports": "^0.23.0",
Expand Down
44 changes: 20 additions & 24 deletions packages/compiler/src/swc/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('swc/core', () => {
expect(output).toMatch(/import\"global\.css\"/);

expect(output).toMatchInlineSnapshot(
`"import{jsx as _jsx}from\\"react/jsx-runtime\\";import{useState}from\\"react\\";import styles from\\"a.css?cssmodules\\";import\\"global.css\\";const App=()=>{const{0:count,1:setCount}=useState(0);return _jsx(\\"div\\",{children:count})};export default App"`
`"import{jsx as _jsx}from"react/jsx-runtime";import{useState}from"react";import styles from"a.css?cssmodules";import"global.css";const App=()=>{const{0:count,1:setCount}=useState(0);return _jsx("div",{children:count})};export default App"`
);
});

Expand Down Expand Up @@ -157,16 +157,14 @@ describe('swc/core', () => {
const code = await swc(`typeof window !== 'undefined';`, {
isNode
});
expect(code).toMatchInlineSnapshot(
`"\\"undefined\\"!==\\"undefined\\""`
);
expect(code).toMatchInlineSnapshot(`""undefined"!=="undefined""`);
});

test('should replace typeof window expression top level', async () => {
const code = await swc(`typeof window !== 'object';`, {
isNode
});
expect(code).toMatchInlineSnapshot(`"\\"undefined\\"!==\\"object\\""`);
expect(code).toMatchInlineSnapshot(`""undefined"!=="object""`);
});
});
});
Expand Down Expand Up @@ -194,7 +192,7 @@ describe('swc/core', () => {
);

expect(output).toMatchInlineSnapshot(
`"import{jsx as _jsx}from\\"react/jsx-runtime\\";import{useState}from\\"react\\";import styles from\\"a.css?cssmodules\\";import\\"global.css\\";var App=function(){var ref=useState(0),count=ref[0],setCount=ref[1];return _jsx(\\"div\\",{children:count})};export default App"`
`"import{jsx as _jsx}from"react/jsx-runtime";import{useState}from"react";import styles from"a.css?cssmodules";import"global.css";var App=function(){var ref=useState(0),count=ref[0],setCount=ref[1];return _jsx("div",{children:count})};export default App"`
);
});

Expand Down Expand Up @@ -232,7 +230,7 @@ describe('swc/core', () => {
isNode
});
expect(code).toMatchInlineSnapshot(
`"function a(){console.log(\\"object\\")}"`
`"function a(){console.log("object")}"`
);
});

Expand All @@ -242,46 +240,44 @@ describe('swc/core', () => {
{ isNode }
);
expect(code).toMatchInlineSnapshot(
`"function a(){console.log(\\"object\\"===\\"undefined\\")}"`
`"function a(){console.log("object"==="undefined")}"`
);
});

test('should replace typeof window expression top level', async () => {
const code = await swc(`typeof window === 'undefined';`, {
isNode
});
expect(code).toMatchInlineSnapshot(`"\\"object\\"===\\"undefined\\""`);
expect(code).toMatchInlineSnapshot(`""object"==="undefined""`);
});

test('should replace typeof window expression top level', async () => {
const code = await swc(`typeof window === 'object';`, {
isNode
});
expect(code).toMatchInlineSnapshot(`"\\"object\\"===\\"object\\""`);
expect(code).toMatchInlineSnapshot(`""object"==="object""`);
});

test('should replace typeof window expression top level', async () => {
const code = await swc(`typeof window !== 'undefined';`, {
isNode
});
expect(code).toMatchInlineSnapshot(`"\\"object\\"!==\\"undefined\\""`);
expect(code).toMatchInlineSnapshot(`""object"!=="undefined""`);
});

test('should replace typeof window expression top level', async () => {
const code = await swc(`typeof window !== 'object';`, {
isNode
});
expect(code).toMatchInlineSnapshot(`"\\"object\\"!==\\"object\\""`);
expect(code).toMatchInlineSnapshot(`""object"!=="object""`);
});
});
});

describe('syntax', () => {
test('should support exportDefaultFrom', async () => {
const code = await swc(`export { default as foo } from "bar"`);
expect(code).toMatchInlineSnapshot(
`"export{default as foo}from\\"bar\\""`
);
expect(code).toMatchInlineSnapshot(`"export{default as foo}from"bar""`);
});

test('should not drop unused exports by default', async () => {
Expand All @@ -298,7 +294,7 @@ describe('swc/core', () => {
`import{e as ee,f as ff}from"f";`
);
expect(code).toMatchInlineSnapshot(
`"import\\"core-js\\";import{foo,bar}from\\"a\\";import baz from\\"b\\";import*as React from\\"react\\";import baz2,{yeet}from\\"c\\";import baz3,{cats}from\\"d\\";import{c,d}from\\"e\\";import{e as ee,f as ff}from\\"f\\""`
`"import"core-js";import{foo,bar}from"a";import baz from"b";import*as React from"react";import baz2,{yeet}from"c";import baz3,{cats}from"d";import{c,d}from"e";import{e as ee,f as ff}from"f""`
);
});

Expand All @@ -320,7 +316,7 @@ describe('swc/core', () => {
{ filename: pageFile }
);
expect(code).toMatchInlineSnapshot(
`"import\\"core-js\\";import{foo,bar}from\\"a\\";import baz from\\"b\\";import*as React from\\"react\\";import baz2,{yeet}from\\"c\\";import baz3,{cats}from\\"d\\";import{c,d}from\\"e\\";import{e as ee,f as ff}from\\"f\\""`
`"import"core-js";import{foo,bar}from"a";import baz from"b";import*as React from"react";import baz2,{yeet}from"c";import baz3,{cats}from"d";import{c,d}from"e";import{e as ee,f as ff}from"f""`
);
});

Expand All @@ -333,7 +329,7 @@ describe('swc/core', () => {
}
);
expect(code).toMatchInlineSnapshot(
`"var hello;export default function(){return(hello===null||hello===void 0?void 0:hello.world)?\\"something\\":\\"nothing\\"}"`
`"var hello;export default function(){return(hello===null||hello===void 0?void 0:hello.world)?"something":"nothing"}"`
);
});

Expand All @@ -346,7 +342,7 @@ describe('swc/core', () => {
}
);
expect(code).toMatchInlineSnapshot(
`"var hello;export default function(){return(hello===null||hello===void 0?void 0:hello.world)?\\"something\\":\\"nothing\\"}"`
`"var hello;export default function(){return(hello===null||hello===void 0?void 0:hello.world)?"something":"nothing"}"`
);
});

Expand All @@ -368,7 +364,7 @@ describe('swc/core', () => {
}
);
expect(code).toMatchInlineSnapshot(
`"var res={status:0,nullVal:null,statusText:\\"\\"};var _status;var status=(_status=res.status)!==null&&_status!==void 0?_status:999;var _nullVal;var nullVal=(_nullVal=res.nullVal)!==null&&_nullVal!==void 0?_nullVal:\\"another\\";var _nullVal1;var statusText=(_nullVal1=res.nullVal)!==null&&_nullVal1!==void 0?_nullVal1:\\"not found\\";export default function(){return\\"hello\\"}"`
`"var res={status:0,nullVal:null,statusText:""};var _status;var status=(_status=res.status)!==null&&_status!==void 0?_status:999;var _nullVal;var nullVal=(_nullVal=res.nullVal)!==null&&_nullVal!==void 0?_nullVal:"another";var _nullVal1;var statusText=(_nullVal1=res.nullVal)!==null&&_nullVal1!==void 0?_nullVal1:"not found";export default function(){return"hello"}"`
);
});

Expand All @@ -390,7 +386,7 @@ describe('swc/core', () => {
}
);
expect(code).toMatchInlineSnapshot(
`"var res={status:0,nullVal:null,statusText:\\"\\"};var _status;var status=(_status=res.status)!==null&&_status!==void 0?_status:999;var _nullVal;var nullVal=(_nullVal=res.nullVal)!==null&&_nullVal!==void 0?_nullVal:\\"another\\";var _nullVal1;var statusText=(_nullVal1=res.nullVal)!==null&&_nullVal1!==void 0?_nullVal1:\\"not found\\";export default function(){return\\"hello\\"}"`
`"var res={status:0,nullVal:null,statusText:""};var _status;var status=(_status=res.status)!==null&&_status!==void 0?_status:999;var _nullVal;var nullVal=(_nullVal=res.nullVal)!==null&&_nullVal!==void 0?_nullVal:"another";var _nullVal1;var statusText=(_nullVal1=res.nullVal)!==null&&_nullVal1!==void 0?_nullVal1:"not found";export default function(){return"hello"}"`
);
});
});
Expand Down Expand Up @@ -428,9 +424,9 @@ describe('swc/core', () => {
);

expect(output).toMatchInlineSnapshot(`
"import Grid from \\"react-bootstrap/lib/Grid\\";
import Row from \\"react-bootstrap/lib/Row\\";
import Col1 from \\"react-bootstrap/lib/Col\\";
"import Grid from "react-bootstrap/lib/Grid";
import Row from "react-bootstrap/lib/Row";
import Col1 from "react-bootstrap/lib/Col";
"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ const swc = async (
describe('auto-css-modules', () => {
test('css modules', async () => {
expect(await swc(`import styles from 'a.css';`)).toMatchInlineSnapshot(`
"import styles from \\"a.css?cssmodules\\";
"import styles from "a.css?cssmodules";
"
`);
expect(await swc(`import styles from 'a.less';`)).toMatchInlineSnapshot(`
"import styles from \\"a.less?cssmodules\\";
"import styles from "a.less?cssmodules";
"
`);
expect(await swc(`import styles from 'a.scss';`)).toMatchInlineSnapshot(`
"import styles from \\"a.scss?cssmodules\\";
"import styles from "a.scss?cssmodules";
"
`);
expect(await swc(`import styles from 'a.sass';`)).toMatchInlineSnapshot(`
"import styles from \\"a.sass?cssmodules\\";
"import styles from "a.sass?cssmodules";
"
`);
});
Expand All @@ -37,29 +37,29 @@ describe('auto-css-modules', () => {
cssModuleFlag: 'foo'
})
).toMatchInlineSnapshot(`
"import styles from \\"a.css?foo\\";
"import styles from "a.css?foo";
"
`);
});

test('no css modules', async () => {
expect(await swc(`import 'a.css';`)).toMatchInlineSnapshot(`
"import \\"a.css\\";
"import "a.css";
"
`);
});

test('do not infect non css imports', async () => {
expect(await swc(`import a from 'a';`)).toMatchInlineSnapshot(`
"import a from \\"a\\";
"import a from "a";
"
`);
expect(await swc(`import a from 'a.js';`)).toMatchInlineSnapshot(`
"import a from \\"a.js\\";
"import a from "a.js";
"
`);
expect(await swc(`import 'a';`)).toMatchInlineSnapshot(`
"import \\"a\\";
"import "a";
"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('dynamic-plugin', () => {
);

expect(output).toMatchInlineSnapshot(
`"import{dynamic}from\\"@shuvi/runtime\\";dynamic(()=>import(\\"./component\\"),{webpack:()=>[require.resolveWeak(\\"./component\\")]})"`
`"import{dynamic}from"@shuvi/runtime";dynamic(()=>import("./component"),{webpack:()=>[require.resolveWeak("./component")]})"`
);
});

Expand All @@ -82,7 +82,7 @@ describe('dynamic-plugin', () => {
);

expect(output).toMatchInlineSnapshot(
`"import React from\\"react\\";import{dynamic}from\\"@shuvi/runtime\\";dynamic(async()=>{await wait(500);return()=>React.createElement(\\"div\\",null,\\"123\\")},{})"`
`"import React from"react";import{dynamic}from"@shuvi/runtime";dynamic(async()=>{await wait(500);return()=>React.createElement("div",null,"123")},{})"`
);
});

Expand All @@ -101,7 +101,7 @@ describe('dynamic-plugin', () => {
}
);
expect(output).toMatchInlineSnapshot(
`"import React from\\"react\\";import{dynamic}from\\"@shuvi/runtime\\";dynamic({loader:()=>import(\\"./component\\")},{webpack:()=>[require.resolveWeak(\\"./component\\")]})"`
`"import React from"react";import{dynamic}from"@shuvi/runtime";dynamic({loader:()=>import("./component")},{webpack:()=>[require.resolveWeak("./component")]})"`
);
});
});
Expand All @@ -121,7 +121,7 @@ describe('dynamic-plugin', () => {
);

expect(output).toMatchInlineSnapshot(
`"import{dynamic}from\\"@shuvi/runtime\\";dynamic(()=>import(\\"./component\\"),{modules:[\\"./component\\"]})"`
`"import{dynamic}from"@shuvi/runtime";dynamic(()=>import("./component"),{modules:["./component"]})"`
);
});

Expand All @@ -142,7 +142,7 @@ describe('dynamic-plugin', () => {
);

expect(output).toMatchInlineSnapshot(
`"import React from\\"react\\";import{dynamic}from\\"@shuvi/runtime\\";dynamic(async()=>{await wait(500);return()=>React.createElement(\\"div\\",null,\\"123\\")},{})"`
`"import React from"react";import{dynamic}from"@shuvi/runtime";dynamic(async()=>{await wait(500);return()=>React.createElement("div",null,"123")},{})"`
);
});

Expand All @@ -161,7 +161,7 @@ describe('dynamic-plugin', () => {
}
);
expect(output).toMatchInlineSnapshot(
`"import React from\\"react\\";import{dynamic}from\\"@shuvi/runtime\\";dynamic({loader:()=>import(\\"./component\\")},{modules:[\\"./component\\"]})"`
`"import React from"react";import{dynamic}from"@shuvi/runtime";dynamic({loader:()=>import("./component")},{modules:["./component"]})"`
);
});
});
Expand Down
Loading

0 comments on commit c5e443f

Please sign in to comment.