From 9c4627b5f7f7386a25f94394de2bc92ee7900adf Mon Sep 17 00:00:00 2001 From: bluwy Date: Sun, 12 Jun 2022 00:18:39 +0800 Subject: [PATCH 1/5] fix!: use type module (revert #1411) --- packages/vitest/package.json | 11 ++++++----- packages/vitest/rollup.config.js | 7 +++---- packages/vitest/src/node/pool.ts | 2 +- packages/vitest/src/runtime/mocker.ts | 2 +- packages/vitest/src/runtime/worker.ts | 2 +- packages/vitest/vitest.mjs | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 880dbe94c695..d5acbf3f51b5 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -1,5 +1,6 @@ { "name": "vitest", + "type": "module", "version": "0.14.2", "description": "A blazing fast unit test framework powered by Vite", "author": "Anthony Fu ", @@ -22,7 +23,7 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs" + "import": "./dist/index.js" }, "./*": "./*", "./globals": { @@ -33,16 +34,16 @@ }, "./node": { "types": "./dist/node.d.ts", - "import": "./dist/node.mjs" + "import": "./dist/node.js" }, "./config": { "types": "./config.d.ts", "require": "./dist/config.cjs", - "import": "./dist/config.mjs" + "import": "./dist/config.js" } }, - "main": "./dist/index.mjs", - "module": "./dist/index.mjs", + "main": "./dist/index.js", + "module": "./dist/index.js", "types": "./dist/index.d.ts", "bin": { "vitest": "./vitest.mjs" diff --git a/packages/vitest/rollup.config.js b/packages/vitest/rollup.config.js index 91d1d15a5c5f..8008ad0bf9ea 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -61,7 +61,6 @@ export default ({ watch }) => [ output: { dir: 'dist', format: 'esm', - entryFileNames: '[name].mjs', chunkFileNames: (chunkInfo) => { const id = chunkInfo.facadeModuleId || Object.keys(chunkInfo.modules).find(i => !i.includes('node_modules') && i.includes('src/')) if (id) { @@ -71,9 +70,9 @@ export default ({ watch }) => [ .filter(i => !['src', 'index', 'dist', 'node_modules'].some(j => i.includes(j)) && i.match(/^[\w_-]+$/))), ) if (parts.length) - return `chunk-${parts.slice(-2).join('-')}.[hash].mjs` + return `chunk-${parts.slice(-2).join('-')}.[hash].js` } - return 'vendor-[name].[hash].mjs' + return 'vendor-[name].[hash].js' }, }, external, @@ -95,7 +94,7 @@ export default ({ watch }) => [ format: 'cjs', }, { - file: 'dist/config.mjs', + file: 'dist/config.js', format: 'esm', }, ], diff --git a/packages/vitest/src/node/pool.ts b/packages/vitest/src/node/pool.ts index 3f170a6bb19d..fb73fc545226 100644 --- a/packages/vitest/src/node/pool.ts +++ b/packages/vitest/src/node/pool.ts @@ -18,7 +18,7 @@ export interface WorkerPool { close: () => Promise } -const workerPath = pathToFileURL(resolve(distDir, './worker.mjs')).href +const workerPath = pathToFileURL(resolve(distDir, './worker.js')).href export function createPool(ctx: Vitest): WorkerPool { const threadsCount = ctx.config.watch diff --git a/packages/vitest/src/runtime/mocker.ts b/packages/vitest/src/runtime/mocker.ts index 17a10ea051ef..b63783aa7453 100644 --- a/packages/vitest/src/runtime/mocker.ts +++ b/packages/vitest/src/runtime/mocker.ts @@ -230,7 +230,7 @@ export class VitestMocker { private async ensureSpy() { if (VitestMocker.spyModule) return - VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, 'spy.mjs'))}`) as typeof import('../integrations/spy') + VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, 'spy.js'))}`) as typeof import('../integrations/spy') } public async requestWithMock(dep: string) { diff --git a/packages/vitest/src/runtime/worker.ts b/packages/vitest/src/runtime/worker.ts index 9159535cecf6..fbb9701e9eff 100644 --- a/packages/vitest/src/runtime/worker.ts +++ b/packages/vitest/src/runtime/worker.ts @@ -38,7 +38,7 @@ async function startViteNode(ctx: WorkerContext) { const { run } = (await executeInViteNode({ files: [ - resolve(distDir, 'entry.mjs'), + resolve(distDir, 'entry.js'), ], fetchModule(id) { return rpc().fetch(id) diff --git a/packages/vitest/vitest.mjs b/packages/vitest/vitest.mjs index dfaf05f626b7..02dd4714b903 100755 --- a/packages/vitest/vitest.mjs +++ b/packages/vitest/vitest.mjs @@ -1,2 +1,2 @@ #!/usr/bin/env node -import './dist/cli.mjs' +import './dist/cli.js' From c9992fe3a89161ace458638d0dc5b8033e0c869e Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 15 Jun 2022 15:15:32 +0800 Subject: [PATCH 2/5] feat: add fake cjs exports --- packages/vitest/package.json | 10 ++++++++-- packages/vitest/rollup.config.js | 27 +++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 847fe3be2703..c4eb18a39e3c 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -22,8 +22,14 @@ ], "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js" + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + }, + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "./*": "./*", "./globals": { diff --git a/packages/vitest/rollup.config.js b/packages/vitest/rollup.config.js index 8008ad0bf9ea..c6da9e68d644 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -56,7 +56,7 @@ const plugins = [ ] export default ({ watch }) => [ - { + defineConfig({ input: entries, output: { dir: 'dist', @@ -78,6 +78,25 @@ export default ({ watch }) => [ external, plugins: [ ...plugins, + { + // Add commonjs files so importing vitest in nodenext or node16 environments work + // without changing the test file extension or package.json type + name: 'shim-cjs-files', + generateBundle() { + this.emitFile({ + id: 'index.d.cts', + type: 'asset', + fileName: 'index.d.cts', + source: 'export * from \'./index.js\'', + }) + this.emitFile({ + id: 'index.cjs', + type: 'asset', + fileName: 'index.cjs', + source: '', + }) + }, + }, !watch && licensePlugin(), ], onwarn(message) { @@ -85,8 +104,8 @@ export default ({ watch }) => [ return console.error(message) }, - }, - { + }), + defineConfig({ input: 'src/config.ts', output: [ { @@ -100,7 +119,7 @@ export default ({ watch }) => [ ], external, plugins, - }, + }), ...dtsEntries.map((input) => { const _external = external // index is vitest default types export From 0f2f0ba7a185370d920bf142af630676f15bb2f3 Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 15 Jun 2022 15:22:50 +0800 Subject: [PATCH 3/5] chore: use real files --- packages/vitest/index.cjs | 0 packages/vitest/index.d.cts | 1 + packages/vitest/package.json | 4 ++-- packages/vitest/rollup.config.js | 19 ------------------- 4 files changed, 3 insertions(+), 21 deletions(-) create mode 100644 packages/vitest/index.cjs create mode 100644 packages/vitest/index.d.cts diff --git a/packages/vitest/index.cjs b/packages/vitest/index.cjs new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/vitest/index.d.cts b/packages/vitest/index.d.cts new file mode 100644 index 000000000000..09e9c9b2a265 --- /dev/null +++ b/packages/vitest/index.d.cts @@ -0,0 +1 @@ +export * from './dist/index.js' diff --git a/packages/vitest/package.json b/packages/vitest/package.json index c4eb18a39e3c..88202c38bcba 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -23,8 +23,8 @@ "exports": { ".": { "require": { - "types": "./dist/index.d.cts", - "default": "./dist/index.cjs" + "types": "./index.d.cts", + "default": "./index.cjs" }, "import": { "types": "./dist/index.d.ts", diff --git a/packages/vitest/rollup.config.js b/packages/vitest/rollup.config.js index c6da9e68d644..017559264191 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -78,25 +78,6 @@ export default ({ watch }) => [ external, plugins: [ ...plugins, - { - // Add commonjs files so importing vitest in nodenext or node16 environments work - // without changing the test file extension or package.json type - name: 'shim-cjs-files', - generateBundle() { - this.emitFile({ - id: 'index.d.cts', - type: 'asset', - fileName: 'index.d.cts', - source: 'export * from \'./index.js\'', - }) - this.emitFile({ - id: 'index.cjs', - type: 'asset', - fileName: 'index.cjs', - source: '', - }) - }, - }, !watch && licensePlugin(), ], onwarn(message) { From 70083e0f7b267becc35bae19b0605b05d2455233 Mon Sep 17 00:00:00 2001 From: bluwy Date: Sat, 17 Sep 2022 17:51:48 +0800 Subject: [PATCH 4/5] fix: handle .mjs url --- packages/vitest/src/node/cli-wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/cli-wrapper.ts b/packages/vitest/src/node/cli-wrapper.ts index 49a528bbce54..4133686c4bfd 100644 --- a/packages/vitest/src/node/cli-wrapper.ts +++ b/packages/vitest/src/node/cli-wrapper.ts @@ -7,7 +7,7 @@ import c from 'picocolors' import { execa } from 'execa' import { EXIT_CODE_RESTART } from '../constants' -const ENTRY = new URL('./cli.mjs', import.meta.url) +const ENTRY = new URL('./cli.js', import.meta.url) /** Arguments passed to Node before the script */ const NODE_ARGS = [ From 317627d3d27717058b3ccacbde27a8a66741a94b Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Fri, 7 Oct 2022 13:27:39 +0200 Subject: [PATCH 5/5] chore: give failing tests more time --- test/fails/test/runner.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fails/test/runner.test.ts b/test/fails/test/runner.test.ts index a39ddef056ce..20e732c3c744 100644 --- a/test/fails/test/runner.test.ts +++ b/test/fails/test/runner.test.ts @@ -34,6 +34,6 @@ describe('should fails', async () => { ?.trim() .replace(root, '') expect(msg).toMatchSnapshot(file) - }, 10000) + }, 30_000) } })