diff --git a/.config/vitest.config.mts b/.config/vitest.config.mts index 45b02dccf..104645a1b 100644 --- a/.config/vitest.config.mts +++ b/.config/vitest.config.mts @@ -1,13 +1,15 @@ import { defineConfig } from 'vitest/config'; import path from 'node:path'; +const isAutoInstallPackage = path.basename(process.cwd()) === 'auto-install'; + export default defineConfig({ test: { // Enable global APIs for CommonJS test files. globals: true, - // Phase 1/2 packages use runtime-style, *.test, and a few named entrypoints. + // Phase 1/2/3 packages use runtime-style, top-level test files, *.test, and a few named entrypoints. include: [ - 'test/test.{js,mjs,cjs,ts,mts,cts}', + 'test/*.{js,mjs,cjs,ts,mts,cts}', 'test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}', 'test/{as-input-plugin,as-output-plugin,form,function,misc,sourcemaps}.{js,mjs,cjs,ts,mts,cts}' ], @@ -20,6 +22,8 @@ export default defineConfig({ '**/test/snapshots/**', '**/test/types.ts' ], + // These tests switch process cwd and invoke package managers; run files serially there. + fileParallelism: !isAutoInstallPackage, // Keep snapshots in the same location used by Ava. resolveSnapshotPath: (testPath, snapExt) => path.join(path.dirname(testPath), 'snapshots', path.basename(testPath) + snapExt) diff --git a/packages/auto-install/package.json b/packages/auto-install/package.json index 1307e04b8..26672ca30 100755 --- a/packages/auto-install/package.json +++ b/packages/auto-install/package.json @@ -28,13 +28,13 @@ "ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov", "ci:lint": "pnpm build && pnpm lint", "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", - "ci:test": "pnpm test -- --verbose", + "ci:test": "pnpm test -- --reporter=verbose", "prebuild": "del-cli dist", "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", "release": "pnpm --workspace-root package:release $(pwd)", - "test": "ava", + "test": "vitest --config ../../.config/vitest.config.mts run", "test:ts": "tsc --noEmit" }, "files": [ @@ -69,15 +69,5 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", - "ava": { - "workerThreads": false, - "files": [ - "!**/fixtures/**", - "!**/output/**", - "!**/helpers/**", - "!**/recipes/**", - "!**/types.ts" - ] - } + "types": "./types/index.d.ts" } diff --git a/packages/auto-install/test/npm-bare.js b/packages/auto-install/test/npm-bare.js index 95469f7f6..dcc5e391d 100644 --- a/packages/auto-install/test/npm-bare.js +++ b/packages/auto-install/test/npm-bare.js @@ -1,7 +1,6 @@ const { readFileSync } = require('fs'); const { join } = require('path'); -const test = require('ava'); const del = require('del'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const { rollup } = require('rollup'); @@ -14,8 +13,7 @@ const input = join(cwd, '../input.js'); process.chdir(cwd); -test('npm, bare', async (t) => { - t.timeout(50000); +test('npm, bare', async () => { await rollup({ input, output: { @@ -24,10 +22,10 @@ test('npm, bare', async (t) => { }, plugins: [autoInstall(), nodeResolve()] }); - t.snapshot(readFileSync('package.json', 'utf-8')); - t.truthy(readFileSync('package-lock.json', 'utf-8').includes('"node-noop"')); -}); + expect(readFileSync('package.json', 'utf-8')).toMatchSnapshot(); + expect(readFileSync('package-lock.json', 'utf-8').includes('"node-noop"')).toBeTruthy(); +}, 50000); -test.after(async () => { +afterAll(async () => { await del(['node_modules', 'package.json', 'package-lock.json']); }); diff --git a/packages/auto-install/test/npm.js b/packages/auto-install/test/npm.js index 02fff0325..012225d6c 100644 --- a/packages/auto-install/test/npm.js +++ b/packages/auto-install/test/npm.js @@ -1,7 +1,6 @@ const { readFileSync, writeFileSync } = require('fs'); const { join } = require('path'); -const test = require('ava'); const del = require('del'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const { rollup } = require('rollup'); @@ -16,10 +15,9 @@ const pkgFile = join(cwd, 'package.json'); process.chdir(cwd); -test('invalid manager', (t) => { - t.timeout(50000); - const error = t.throws( - () => +test('invalid manager', () => { + const error = (() => { + try { rollup({ input, output: { @@ -27,16 +25,19 @@ test('invalid manager', (t) => { format: 'cjs' }, plugins: [autoInstall({ pkgFile, manager: 'foo' }), nodeResolve()] - }), - { - instanceOf: RangeError + }); + } catch (caught) { + return caught; } - ); - t.snapshot(error.message); -}); -test('npm', async (t) => { - t.timeout(50000); + return null; + })(); + + expect(error).toBeInstanceOf(RangeError); + expect(error.message).toMatchSnapshot(); +}, 50000); + +test('npm', async () => { await rollup({ input, output: { @@ -45,10 +46,10 @@ test('npm', async (t) => { }, plugins: [autoInstall({ pkgFile, manager }), nodeResolve()] }); - t.snapshot(readFileSync('package.json', 'utf-8')); -}); + expect(readFileSync('package.json', 'utf-8')).toMatchSnapshot(); +}, 50000); -test.after(async () => { +afterAll(async () => { await del(['node_modules', 'package-lock.json']); writeFileSync(pkgFile, '{}'); }); diff --git a/packages/auto-install/test/pnpm-bare.js b/packages/auto-install/test/pnpm-bare.js index acb8aea9a..690592b02 100644 --- a/packages/auto-install/test/pnpm-bare.js +++ b/packages/auto-install/test/pnpm-bare.js @@ -1,7 +1,6 @@ const { readFileSync } = require('fs'); const { join } = require('path'); -const test = require('ava'); const del = require('del'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const { rollup } = require('rollup'); @@ -14,8 +13,7 @@ const input = join(cwd, '../input.js'); process.chdir(cwd); -test('pnpm, bare', async (t) => { - t.timeout(50000); +test('pnpm, bare', async () => { await rollup({ input, output: { @@ -26,9 +24,9 @@ test('pnpm, bare', async (t) => { }); const json = JSON.parse(readFileSync('package.json', 'utf-8')); // snapshots for this are a nightmare cross-platform - t.truthy('node-noop' in json.dependencies); -}); + expect('node-noop' in json.dependencies).toBeTruthy(); +}, 50000); -test.after(async () => { +afterAll(async () => { await del(['node_modules', 'package.json', 'pnpm-lock.yaml']); }); diff --git a/packages/auto-install/test/pnpm.js b/packages/auto-install/test/pnpm.js index 2fe1e5856..3be105293 100644 --- a/packages/auto-install/test/pnpm.js +++ b/packages/auto-install/test/pnpm.js @@ -1,7 +1,6 @@ const { readFileSync, writeFileSync } = require('fs'); const { join } = require('path'); -const test = require('ava'); const del = require('del'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const { rollup } = require('rollup'); @@ -14,8 +13,7 @@ const input = join(cwd, '../input.js'); process.chdir(cwd); -test('pnpm', async (t) => { - t.timeout(50000); +test('pnpm', async () => { await rollup({ input, output: { @@ -27,10 +25,10 @@ test('pnpm', async (t) => { const json = JSON.parse(readFileSync('package.json', 'utf-8')); // snapshots for this are a nightmare cross-platform - t.truthy('node-noop' in json.dependencies); -}); + expect('node-noop' in json.dependencies).toBeTruthy(); +}, 50000); -test.after(async () => { +afterAll(async () => { await del(['node_modules', 'package.json']); writeFileSync('pnpm-lock.yaml', ''); }); diff --git a/packages/auto-install/test/snapshots/npm-bare.js.snap b/packages/auto-install/test/snapshots/npm-bare.js.snap index b4e4b4875..99e5a1ff2 100644 Binary files a/packages/auto-install/test/snapshots/npm-bare.js.snap and b/packages/auto-install/test/snapshots/npm-bare.js.snap differ diff --git a/packages/auto-install/test/snapshots/npm.js.snap b/packages/auto-install/test/snapshots/npm.js.snap index d3c36cb01..e0d414563 100644 Binary files a/packages/auto-install/test/snapshots/npm.js.snap and b/packages/auto-install/test/snapshots/npm.js.snap differ diff --git a/packages/auto-install/test/yarn-bare.js b/packages/auto-install/test/yarn-bare.js index 6b991594e..eeb6b1b75 100644 --- a/packages/auto-install/test/yarn-bare.js +++ b/packages/auto-install/test/yarn-bare.js @@ -1,7 +1,6 @@ const { readFileSync } = require('fs'); const { join } = require('path'); -const test = require('ava'); const del = require('del'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const { rollup } = require('rollup'); @@ -14,8 +13,7 @@ const input = join(cwd, '../input.js'); process.chdir(cwd); -test('yarn, bare', async (t) => { - t.timeout(50000); +test('yarn, bare', async () => { await rollup({ input, output: { @@ -30,9 +28,9 @@ test('yarn, bare', async (t) => { }); const lockFile = readFileSync('yarn.lock', 'utf-8'); // snapshots for this are a nightmare cross-platform - t.truthy(/yarn\.bare\s+node-noop/.test(lockFile)); -}); + expect(/yarn\.bare\s+node-noop/.test(lockFile)).toBeTruthy(); +}, 50000); -test.after(async () => { +afterAll(async () => { await del(['node_modules', 'package.json', 'yarn.lock']); }); diff --git a/packages/auto-install/test/yarn.js b/packages/auto-install/test/yarn.js index 70f86e23a..e001c6ab6 100644 --- a/packages/auto-install/test/yarn.js +++ b/packages/auto-install/test/yarn.js @@ -1,7 +1,6 @@ const { readFileSync, writeFileSync } = require('fs'); const { join } = require('path'); -const test = require('ava'); const del = require('del'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const { rollup } = require('rollup'); @@ -14,8 +13,7 @@ const input = join(cwd, '../input.js'); process.chdir(cwd); -test('yarn', async (t) => { - t.timeout(50000); +test('yarn', async () => { await rollup({ input, output: { @@ -27,10 +25,10 @@ test('yarn', async (t) => { }); const lockFile = readFileSync('yarn.lock', 'utf-8'); // snapshots for this are a nightmare cross-platform - t.truthy(/yarn\s+node-noop/.test(lockFile)); -}); + expect(/yarn\s+node-noop/.test(lockFile)).toBeTruthy(); +}, 50000); -test.after(async () => { +afterAll(async () => { await del(['node_modules', 'package.json']); writeFileSync('yarn.lock', ''); }); diff --git a/packages/pluginutils/package.json b/packages/pluginutils/package.json index 1dc8e299d..80c0ab80d 100644 --- a/packages/pluginutils/package.json +++ b/packages/pluginutils/package.json @@ -31,13 +31,13 @@ "ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov", "ci:lint": "pnpm build && pnpm lint", "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", - "ci:test": "pnpm test -- --verbose", + "ci:test": "pnpm test -- --reporter=verbose", "prebuild": "del-cli dist", "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build --sourcemap", "release": "pnpm --workspace-root package:release $(pwd)", - "test": "ava", + "test": "vitest --config ../../.config/vitest.config.mts run", "test:ts": "tsc --noEmit" }, "files": [ @@ -76,21 +76,6 @@ "typescript": "^4.8.3" }, "types": "./types/index.d.ts", - "ava": { - "extensions": [ - "ts" - ], - "require": [ - "ts-node/register" - ], - "workerThreads": false, - "files": [ - "!**/fixtures/**", - "!**/helpers/**", - "!**/recipes/**", - "!**/types.ts" - ] - }, "nyc": { "extension": [ ".js", diff --git a/packages/pluginutils/test/addExtension.ts b/packages/pluginutils/test/addExtension.ts index 7daf7ed62..c22cf12c5 100755 --- a/packages/pluginutils/test/addExtension.ts +++ b/packages/pluginutils/test/addExtension.ts @@ -1,26 +1,24 @@ -import test from 'ava'; - import { addExtension } from '../'; -test('adds .js to an ID without an extension', (t) => { - t.is(addExtension('foo'), 'foo.js'); +test('adds .js to an ID without an extension', () => { + expect(addExtension('foo')).toBe('foo.js'); }); -test('ignores file with existing extension', (t) => { - t.is(addExtension('foo.js'), 'foo.js'); - t.is(addExtension('foo.json'), 'foo.json'); +test('ignores file with existing extension', () => { + expect(addExtension('foo.js')).toBe('foo.js'); + expect(addExtension('foo.json')).toBe('foo.json'); }); -test('ignores file with trailing dot', (t) => { - t.is(addExtension('foo.'), 'foo.'); +test('ignores file with trailing dot', () => { + expect(addExtension('foo.')).toBe('foo.'); }); -test('ignores leading .', (t) => { - t.is(addExtension('./foo'), './foo.js'); - t.is(addExtension('./foo.js'), './foo.js'); +test('ignores leading .', () => { + expect(addExtension('./foo')).toBe('./foo.js'); + expect(addExtension('./foo.js')).toBe('./foo.js'); }); -test('adds a custom extension', (t) => { - t.is(addExtension('foo', '.wut'), 'foo.wut'); - t.is(addExtension('foo.lol', '.wut'), 'foo.lol'); +test('adds a custom extension', () => { + expect(addExtension('foo', '.wut')).toBe('foo.wut'); + expect(addExtension('foo.lol', '.wut')).toBe('foo.lol'); }); diff --git a/packages/pluginutils/test/attachScopes.ts b/packages/pluginutils/test/attachScopes.ts index 1f82eb002..49f9d07c0 100755 --- a/packages/pluginutils/test/attachScopes.ts +++ b/packages/pluginutils/test/attachScopes.ts @@ -1,80 +1,79 @@ import type * as estree from 'estree'; -import test from 'ava'; import { parse } from 'acorn'; import type { AttachedScope } from '../'; import { attachScopes } from '../'; -test('attaches a scope to the top level', (t) => { +test('attaches a scope to the top level', () => { const ast = parse('var foo;', { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('foo')); - t.falsy(scope.contains('bar')); + expect(scope.contains('foo')).toBeTruthy(); + expect(scope.contains('bar')).toBeFalsy(); }); -test('adds multiple declarators from a single var declaration', (t) => { +test('adds multiple declarators from a single var declaration', () => { const ast = parse('var foo, bar;', { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('foo')); - t.truthy(scope.contains('bar')); + expect(scope.contains('foo')).toBeTruthy(); + expect(scope.contains('bar')).toBeTruthy(); }); -test('adds named declarators from a deconstructed declaration', (t) => { +test('adds named declarators from a deconstructed declaration', () => { const ast = parse("var {1: a, b} = {1: 'a', b: 'b'};", { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('a')); - t.truthy(scope.contains('b')); + expect(scope.contains('a')).toBeTruthy(); + expect(scope.contains('b')).toBeTruthy(); }); -test('adds rest elements from a deconstructed object declaration', (t) => { +test('adds rest elements from a deconstructed object declaration', () => { const ast = parse('const {x, y: z, ...rest} = {x: 10, y: 20, z: 30, w: 40, k: 50};', { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('x')); - t.falsy(scope.contains('y')); - t.truthy(scope.contains('z')); - t.truthy(scope.contains('rest')); + expect(scope.contains('x')).toBeTruthy(); + expect(scope.contains('y')).toBeFalsy(); + expect(scope.contains('z')).toBeTruthy(); + expect(scope.contains('rest')).toBeTruthy(); }); -test('adds nested declarators from a deconstructed declaration', (t) => { +test('adds nested declarators from a deconstructed declaration', () => { const ast = parse("let {a: {b: c}} = {a: {b: 'b'}};", { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); - t.truthy(scope.contains('c')); + expect(scope.contains('a')).toBeFalsy(); + expect(scope.contains('b')).toBeFalsy(); + expect(scope.contains('c')).toBeTruthy(); }); -test('supports FunctionDeclarations without id', (t) => { +test('supports FunctionDeclarations without id', () => { const ast = parse('export default function () {}', { ecmaVersion: 2020, sourceType: 'module' }); - t.notThrows(() => { + expect(() => { attachScopes(ast, 'scope'); - }); + }).not.toThrow(); }); -test('supports catch without a parameter', (t) => { +test('supports catch without a parameter', () => { const ast = parse('try {} catch {}', { ecmaVersion: 2020, sourceType: 'script' }); - t.notThrows(() => { + expect(() => { attachScopes(ast, 'scope'); - }); + }).not.toThrow(); }); -test('supports ForStatement', (t) => { +test('supports ForStatement', () => { const ast = parse( ` for (let a = 0; a < 10; a++) { @@ -86,20 +85,20 @@ test('supports ForStatement', (t) => { ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); + expect(scope.contains('a')).toBeFalsy(); + expect(scope.contains('b')).toBeFalsy(); const forLoop = ast.body[0] as estree.ForStatement & { scope: AttachedScope }; - t.truthy(forLoop.scope.contains('a')); - t.falsy(forLoop.scope.contains('b')); + expect(forLoop.scope.contains('a')).toBeTruthy(); + expect(forLoop.scope.contains('b')).toBeFalsy(); const forBody = forLoop.body as estree.BlockStatement & { scope: AttachedScope }; - t.truthy(forBody.scope.contains('a')); - t.truthy(forBody.scope.contains('b')); + expect(forBody.scope.contains('a')).toBeTruthy(); + expect(forBody.scope.contains('b')).toBeTruthy(); }); -test('supports ForOfStatement', (t) => { +test('supports ForOfStatement', () => { const ast = parse( ` for (const a of [1, 2, 3]) { @@ -111,19 +110,19 @@ test('supports ForOfStatement', (t) => { ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); + expect(scope.contains('a')).toBeFalsy(); + expect(scope.contains('b')).toBeFalsy(); const forLoop = ast.body[0] as estree.ForOfStatement & { scope: AttachedScope }; - t.truthy(forLoop.scope.contains('a')); - t.falsy(forLoop.scope.contains('b')); + expect(forLoop.scope.contains('a')).toBeTruthy(); + expect(forLoop.scope.contains('b')).toBeFalsy(); const forBody = forLoop.body as estree.BlockStatement & { scope: AttachedScope }; - t.truthy(forBody.scope.contains('a')); - t.truthy(forBody.scope.contains('b')); + expect(forBody.scope.contains('a')).toBeTruthy(); + expect(forBody.scope.contains('b')).toBeTruthy(); }); -test('supports ForInStatement', (t) => { +test('supports ForInStatement', () => { const ast = parse( ` for (let a in [1, 2, 3]) { @@ -135,14 +134,14 @@ test('supports ForInStatement', (t) => { ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); + expect(scope.contains('a')).toBeFalsy(); + expect(scope.contains('b')).toBeFalsy(); const forLoop = ast.body[0] as estree.ForInStatement & { scope: AttachedScope }; - t.truthy(forLoop.scope.contains('a')); - t.falsy(forLoop.scope.contains('b')); + expect(forLoop.scope.contains('a')).toBeTruthy(); + expect(forLoop.scope.contains('b')).toBeFalsy(); const forBody = forLoop.body as estree.BlockStatement & { scope: AttachedScope }; - t.truthy(forBody.scope.contains('a')); - t.truthy(forBody.scope.contains('b')); + expect(forBody.scope.contains('a')).toBeTruthy(); + expect(forBody.scope.contains('b')).toBeTruthy(); }); diff --git a/packages/pluginutils/test/createFilter.ts b/packages/pluginutils/test/createFilter.ts index 783182eac..fbbb27f23 100755 --- a/packages/pluginutils/test/createFilter.ts +++ b/packages/pluginutils/test/createFilter.ts @@ -1,170 +1,168 @@ import { resolve as rawResolve } from 'path'; -import test from 'ava'; - import { createFilter, normalizePath } from '../'; const resolve = (...parts: string[]) => normalizePath(rawResolve(...parts)); -test.beforeEach(() => process.chdir(__dirname)); +beforeEach(() => process.chdir(__dirname)); -test('includes by default ', (t) => { +test('includes by default ', () => { const filter = createFilter(); - t.truthy(filter(resolve('x'))); + expect(filter(resolve('x'))).toBeTruthy(); }); -test('excludes IDs that are not included, if include.length > 0', (t) => { +test('excludes IDs that are not included, if include.length > 0', () => { const filter = createFilter(['y']); - t.falsy(filter(resolve('x'))); - t.truthy(filter(resolve('y'))); + expect(filter(resolve('x'))).toBeFalsy(); + expect(filter(resolve('y'))).toBeTruthy(); }); -test('excludes IDs explicitly', (t) => { +test('excludes IDs explicitly', () => { const filter = createFilter(null, ['y']); - t.truthy(filter(resolve('x'))); - t.falsy(filter(resolve('y'))); + expect(filter(resolve('x'))).toBeTruthy(); + expect(filter(resolve('y'))).toBeFalsy(); }); -test('handles non-array arguments', (t) => { +test('handles non-array arguments', () => { const filter = createFilter('foo/*', 'foo/baz'); - t.truthy(filter(resolve('foo/bar'))); - t.falsy(filter(resolve('foo/baz'))); + expect(filter(resolve('foo/bar'))).toBeTruthy(); + expect(filter(resolve('foo/baz'))).toBeFalsy(); }); -test('negation patterns', (t) => { +test('negation patterns', () => { const filter = createFilter(['a/!(b)/c']); - t.truthy(filter(resolve('a/d/c'))); - t.falsy(filter(resolve('a/b/c'))); + expect(filter(resolve('a/d/c'))).toBeTruthy(); + expect(filter(resolve('a/b/c'))).toBeFalsy(); }); -test('excludes non-string IDs', (t) => { +test('excludes non-string IDs', () => { const filter = createFilter(null, null); - t.falsy(filter({})); + expect(filter({})).toBeFalsy(); }); -test('excludes strings beginning with NUL', (t) => { +test('excludes strings beginning with NUL', () => { const filter = createFilter(null, null); - t.falsy(filter('\0someid')); + expect(filter('\0someid')).toBeFalsy(); }); -test('includes with regexp', (t) => { +test('includes with regexp', () => { const filter = createFilter(['a/!(b)/c', /\.js$/]); - t.truthy(filter(resolve('a/d/c'))); - t.falsy(filter(resolve('a/b/c'))); - t.truthy(filter(resolve('a.js'))); - t.truthy(filter(resolve('a/b.js'))); - t.falsy(filter(resolve('a/b.jsx'))); + expect(filter(resolve('a/d/c'))).toBeTruthy(); + expect(filter(resolve('a/b/c'))).toBeFalsy(); + expect(filter(resolve('a.js'))).toBeTruthy(); + expect(filter(resolve('a/b.js'))).toBeTruthy(); + expect(filter(resolve('a/b.jsx'))).toBeFalsy(); }); -test('excludes with regexp', (t) => { +test('excludes with regexp', () => { const filter = createFilter(['a/!(b)/c', /\.js$/], /\.js$/); - t.truthy(filter(resolve('a/d/c'))); - t.falsy(filter(resolve('a/b/c'))); - t.falsy(filter(resolve('a.js'))); - t.falsy(filter(resolve('a/b.js'))); - t.falsy(filter(resolve('a/b.jsx'))); + expect(filter(resolve('a/d/c'))).toBeTruthy(); + expect(filter(resolve('a/b/c'))).toBeFalsy(); + expect(filter(resolve('a.js'))).toBeFalsy(); + expect(filter(resolve('a/b.js'))).toBeFalsy(); + expect(filter(resolve('a/b.jsx'))).toBeFalsy(); }); -test('allows setting an absolute base dir', (t) => { +test('allows setting an absolute base dir', () => { const baseDir = resolve('C'); const filter = createFilter(['y*'], ['yx'], { resolve: baseDir }); - t.falsy(filter(`${baseDir}/x`)); - t.truthy(filter(`${baseDir}/ys`)); - t.falsy(filter(`${baseDir}/yx`)); - t.falsy(filter(resolve('C/d/ys'))); - t.falsy(filter(resolve('ys'))); - t.falsy(filter('ys')); + expect(filter(`${baseDir}/x`)).toBeFalsy(); + expect(filter(`${baseDir}/ys`)).toBeTruthy(); + expect(filter(`${baseDir}/yx`)).toBeFalsy(); + expect(filter(resolve('C/d/ys'))).toBeFalsy(); + expect(filter(resolve('ys'))).toBeFalsy(); + expect(filter('ys')).toBeFalsy(); }); -test('allows setting a relative base dir', (t) => { +test('allows setting a relative base dir', () => { const filter = createFilter(['y*'], ['yx'], { resolve: 'C/d' }); - t.falsy(filter(resolve('C/d/x'))); - t.truthy(filter(resolve('C/d/ys'))); - t.falsy(filter(resolve('C/d/yx'))); - t.falsy(filter(`${resolve('C')}/ys`)); - t.falsy(filter(resolve('ys'))); - t.falsy(filter('ys')); + expect(filter(resolve('C/d/x'))).toBeFalsy(); + expect(filter(resolve('C/d/ys'))).toBeTruthy(); + expect(filter(resolve('C/d/yx'))).toBeFalsy(); + expect(filter(`${resolve('C')}/ys`)).toBeFalsy(); + expect(filter(resolve('ys'))).toBeFalsy(); + expect(filter('ys')).toBeFalsy(); }); -test('ignores a falsy resolve value', (t) => { +test('ignores a falsy resolve value', () => { const filter = createFilter(['y*'], ['yx'], { resolve: null }); - t.falsy(filter(resolve('x'))); - t.truthy(filter(resolve('ys'))); - t.falsy(filter(resolve('yx'))); - t.falsy(filter(`${resolve('C')}/ys`)); - t.falsy(filter(resolve('C/d/ys'))); - t.falsy(filter('ys')); + expect(filter(resolve('x'))).toBeFalsy(); + expect(filter(resolve('ys'))).toBeTruthy(); + expect(filter(resolve('yx'))).toBeFalsy(); + expect(filter(`${resolve('C')}/ys`)).toBeFalsy(); + expect(filter(resolve('C/d/ys'))).toBeFalsy(); + expect(filter('ys')).toBeFalsy(); }); -test('allows preventing resolution against process.cwd()', (t) => { +test('allows preventing resolution against process.cwd()', () => { const filter = createFilter(['y*'], ['yx'], { resolve: false }); - t.falsy(filter('x')); - t.truthy(filter('ys')); - t.falsy(filter('yx')); - t.falsy(filter(`${resolve('C')}/ys`)); - t.falsy(filter(resolve('C/d/ys'))); - t.falsy(filter(resolve('ys'))); + expect(filter('x')).toBeFalsy(); + expect(filter('ys')).toBeTruthy(); + expect(filter('yx')).toBeFalsy(); + expect(filter(`${resolve('C')}/ys`)).toBeFalsy(); + expect(filter(resolve('C/d/ys'))).toBeFalsy(); + expect(filter(resolve('ys'))).toBeFalsy(); }); -test('includes names starting with a "."', (t) => { +test('includes names starting with a "."', () => { const filter = createFilter(['**/*a']); - t.truthy(filter(resolve('.a'))); - t.truthy(filter(resolve('.x/a'))); + expect(filter(resolve('.a'))).toBeTruthy(); + expect(filter(resolve('.x/a'))).toBeTruthy(); }); -test.serial('includes names containing parenthesis', (t) => { +test.sequential('includes names containing parenthesis', () => { process.chdir(resolve(__dirname, 'fixtures/folder-with (parens)')); const filter = createFilter(['*.ts+(|x)', '**/*.ts+(|x)'], ['*.d.ts', '**/*.d.ts']); - t.truthy(filter(resolve('folder (test)/src/main.tsx'))); - t.truthy(filter(resolve('.x/(test)a.ts'))); - t.falsy(filter(resolve('.x/(test)a.d.ts'))); + expect(filter(resolve('folder (test)/src/main.tsx'))).toBeTruthy(); + expect(filter(resolve('.x/(test)a.ts'))).toBeTruthy(); + expect(filter(resolve('.x/(test)a.d.ts'))).toBeFalsy(); }); -test('handles relative paths', (t) => { +test('handles relative paths', () => { const filter = createFilter(['./index.js', './foo/../a.js']); - t.truthy(filter(resolve('index.js'))); - t.truthy(filter(resolve('a.js'))); - t.falsy(filter(resolve('foo/a.js'))); + expect(filter(resolve('index.js'))).toBeTruthy(); + expect(filter(resolve('a.js'))).toBeTruthy(); + expect(filter(resolve('foo/a.js'))).toBeFalsy(); }); -test('does not add current working directory when pattern is an absolute path', (t) => { +test('does not add current working directory when pattern is an absolute path', () => { const filter = createFilter([resolve('..', '..', '*')]); - t.truthy(filter(resolve('..', '..', 'a'))); - t.truthy(filter(resolve('..', '..', 'b'))); - t.falsy(filter(resolve('..', 'c'))); + expect(filter(resolve('..', '..', 'a'))).toBeTruthy(); + expect(filter(resolve('..', '..', 'b'))).toBeTruthy(); + expect(filter(resolve('..', 'c'))).toBeFalsy(); }); -test('does not add current working directory when pattern starts with character **', (t) => { +test('does not add current working directory when pattern starts with character **', () => { const filter = createFilter(['**/*']); - t.truthy(filter(resolve('a'))); - t.truthy(filter(resolve('..', '..', 'a'))); + expect(filter(resolve('a'))).toBeTruthy(); + expect(filter(resolve('..', '..', 'a'))).toBeTruthy(); }); -test('add current working directory when pattern starts with one *', (t) => { +test('add current working directory when pattern starts with one *', () => { const filter = createFilter([`*`]); - t.truthy(filter(resolve('a'))); - t.falsy(filter(resolve('..', '..', 'a'))); + expect(filter(resolve('a'))).toBeTruthy(); + expect(filter(resolve('..', '..', 'a'))).toBeFalsy(); }); -test('normalizes path when pattern is an absolute path', (t) => { +test('normalizes path when pattern is an absolute path', () => { const filterPosix = createFilter([`${resolve('.')}/*`]); const filterWin = createFilter([`${resolve('.')}\\*`]); - t.truthy(filterPosix(resolve('a'))); - t.truthy(filterWin(resolve('a'))); + expect(filterPosix(resolve('a'))).toBeTruthy(); + expect(filterWin(resolve('a'))).toBeTruthy(); }); -test('normalizes path when pattern starts with *', (t) => { +test('normalizes path when pattern starts with *', () => { const filterPosix = createFilter([`**/a`]); const filterWin = createFilter([`**\\a`]); - t.truthy(filterPosix(resolve('a'))); - t.truthy(filterWin(resolve('a'))); + expect(filterPosix(resolve('a'))).toBeTruthy(); + expect(filterWin(resolve('a'))).toBeTruthy(); }); -test('normalizes path when pattern has resolution base', (t) => { +test('normalizes path when pattern has resolution base', () => { const filterPosix = createFilter([`test/*`], [], { resolve: __dirname }); @@ -172,30 +170,30 @@ test('normalizes path when pattern has resolution base', (t) => { resolve: __dirname }); - t.truthy(filterPosix(resolve('test/a'))); - t.truthy(filterWin(resolve('test/a'))); + expect(filterPosix(resolve('test/a'))).toBeTruthy(); + expect(filterWin(resolve('test/a'))).toBeTruthy(); }); -test('pass a regular expression to the include parameter', (t) => { +test('pass a regular expression to the include parameter', () => { const filter = createFilter([/zxcvbnmasdfg/]); - t.truthy(filter(resolve('zxcvbnmasdfg'))); - t.falsy(filter(resolve('zxcvbnmasdfe'))); + expect(filter(resolve('zxcvbnmasdfg'))).toBeTruthy(); + expect(filter(resolve('zxcvbnmasdfe'))).toBeFalsy(); }); -test('pass a regular expression to the include parameter with g flag', (t) => { +test('pass a regular expression to the include parameter with g flag', () => { const filter = createFilter([/zxcvbnmasdfg/g]); - t.truthy(filter(resolve('zxcvbnmasdfg'))); - t.truthy(filter(resolve('zxcvbnmasdfg'))); + expect(filter(resolve('zxcvbnmasdfg'))).toBeTruthy(); + expect(filter(resolve('zxcvbnmasdfg'))).toBeTruthy(); }); -test('pass a regular expression to the exclude parameter', (t) => { +test('pass a regular expression to the exclude parameter', () => { const filter = createFilter(null, [/zxcvbnmasdfg/]); - t.falsy(filter(resolve('zxcvbnmasdfg'))); - t.truthy(filter(resolve('zxcvbnmasdfe'))); + expect(filter(resolve('zxcvbnmasdfg'))).toBeFalsy(); + expect(filter(resolve('zxcvbnmasdfe'))).toBeTruthy(); }); -test('pass a regular expression to the exclude parameter with g flag', (t) => { +test('pass a regular expression to the exclude parameter with g flag', () => { const filter = createFilter(null, [/zxcvbnmasdfg/g]); - t.falsy(filter(resolve('zxcvbnmasdfg'))); - t.falsy(filter(resolve('zxcvbnmasdfg'))); + expect(filter(resolve('zxcvbnmasdfg'))).toBeFalsy(); + expect(filter(resolve('zxcvbnmasdfg'))).toBeFalsy(); }); diff --git a/packages/pluginutils/test/dataToEsm.ts b/packages/pluginutils/test/dataToEsm.ts index d32fe3e24..c43504a2e 100755 --- a/packages/pluginutils/test/dataToEsm.ts +++ b/packages/pluginutils/test/dataToEsm.ts @@ -1,129 +1,118 @@ -import test from 'ava'; - import { dataToEsm } from '../'; -test('support bigint', (t) => { - t.is( - dataToEsm({ positive: BigInt('0'), negative: BigInt('-1') }), +test('support bigint', () => { + expect(dataToEsm({ positive: BigInt('0'), negative: BigInt('-1') })).toBe( 'export var positive = 0n;\nexport var negative = -1n;\nexport default {\n\tpositive: positive,\n\tnegative: negative\n};\n' ); }); -test('support symbol', (t) => { - t.is( - dataToEsm({ normal: Symbol.for('key'), empty: Symbol.for('') }), +test('support symbol', () => { + expect(dataToEsm({ normal: Symbol.for('key'), empty: Symbol.for('') })).toBe( 'export var normal = Symbol.for("key");\nexport var empty = Symbol.for("");\nexport default {\n\tnormal: normal,\n\tempty: empty\n};\n' ); }); -test('outputs treeshakeable data', (t) => { - t.is( - dataToEsm({ some: 'data', another: 'data' }), +test('outputs treeshakeable data', () => { + expect(dataToEsm({ some: 'data', another: 'data' })).toBe( 'export var some = "data";\nexport var another = "data";\nexport default {\n\tsome: some,\n\tanother: another\n};\n' ); }); -test('handles illegal identifiers, object shorthand, preferConst', (t) => { - t.is( - dataToEsm({ '1': 'data', default: 'data' }, { objectShorthand: true, preferConst: true }), - 'export default {\n\t"1": "data",\n\t"default": "data"\n};\n' - ); +test('handles illegal identifiers, object shorthand, preferConst', () => { + expect( + dataToEsm({ '1': 'data', default: 'data' }, { objectShorthand: true, preferConst: true }) + ).toBe('export default {\n\t"1": "data",\n\t"default": "data"\n};\n'); }); -test('supports non-JSON data', (t) => { +test('supports non-JSON data', () => { const date = new Date(); - t.is( - dataToEsm({ inf: -Infinity, date, number: NaN, regexp: /.*/ }), + expect(dataToEsm({ inf: -Infinity, date, number: NaN, regexp: /.*/ })).toBe( `export var inf = -Infinity;\nexport var date = new Date(${date.getTime()});\nexport var number = NaN;\nexport var regexp = /.*/;\nexport default {\n\tinf: inf,\n\tdate: date,\n\tnumber: number,\n\tregexp: regexp\n};\n` ); }); -test('supports a compact argument', (t) => { - t.is( - dataToEsm({ some: 'data', another: 'data' }, { compact: true, objectShorthand: true }), - 'export var some="data";export var another="data";export default{some,another};' - ); - t.is( +test('supports a compact argument', () => { + expect( + dataToEsm({ some: 'data', another: 'data' }, { compact: true, objectShorthand: true }) + ).toBe('export var some="data";export var another="data";export default{some,another};'); + expect( dataToEsm( { some: { deep: { object: 'definition', here: 'here' } }, else: { deep: { object: 'definition', here: 'here' } } }, { compact: true, objectShorthand: false } - ), + ) + ).toBe( 'export var some={deep:{object:"definition",here:"here"}};export default{some:some,"else":{deep:{object:"definition",here:"here"}}};' ); }); -test('supports nested objects', (t) => { +test('supports nested objects', () => { const obj = { a: { b: 'c', d: ['e', 'f'] } }; - t.is( - dataToEsm({ obj }), + expect(dataToEsm({ obj })).toBe( 'export var obj = {\n\ta: {\n\t\tb: "c",\n\t\td: [\n\t\t\t"e",\n\t\t\t"f"\n\t\t]\n\t}\n};\nexport default {\n\tobj: obj\n};\n' ); }); -test('supports nested arrays', (t) => { +test('supports nested arrays', () => { const arr = ['a', 'b']; - t.is( - dataToEsm({ arr }), + expect(dataToEsm({ arr })).toBe( 'export var arr = [\n\t"a",\n\t"b"\n];\nexport default {\n\tarr: arr\n};\n' ); }); -test('serializes null', (t) => { - t.is(dataToEsm({ null: null }), 'export default {\n\t"null": null\n};\n'); +test('serializes null', () => { + expect(dataToEsm({ null: null })).toBe('export default {\n\t"null": null\n};\n'); }); -test('supports default only', (t) => { +test('supports default only', () => { const arr = ['a', 'b']; - t.is( - dataToEsm({ arr }, { namedExports: false }), + expect(dataToEsm({ arr }, { namedExports: false })).toBe( 'export default {\n\tarr: [\n\t\t"a",\n\t\t"b"\n\t]\n};' ); }); -test('exports default only for arrays', (t) => { +test('exports default only for arrays', () => { const arr = ['a', 'b']; - t.is(dataToEsm(arr), 'export default [\n\t"a",\n\t"b"\n];'); + expect(dataToEsm(arr)).toBe('export default [\n\t"a",\n\t"b"\n];'); }); -test('exports default only for null', (t) => { - t.is(dataToEsm(null, { compact: true }), 'export default null;'); +test('exports default only for null', () => { + expect(dataToEsm(null, { compact: true })).toBe('export default null;'); }); -test('exports default only for primitive values', (t) => { - t.is(dataToEsm('some string'), 'export default "some string";'); +test('exports default only for primitive values', () => { + expect(dataToEsm('some string')).toBe('export default "some string";'); }); -test('supports empty keys', (t) => { - t.is( - dataToEsm({ a: 'x', '': 'y' }), +test('supports empty keys', () => { + expect(dataToEsm({ a: 'x', '': 'y' })).toBe( 'export var a = "x";\nexport default {\n\ta: a,\n\t"": "y"\n};\n' ); }); -test('avoid U+2029 U+2029 -0 be ignored by JSON.stringify, and avoid it return non-string (undefined) before replacing', (t) => { - t.is( - // eslint-disable-next-line no-undefined, func-names - dataToEsm([-0, '\u2028\u2029', undefined, function () {}], { compact: true }), +test('avoid U+2029 U+2029 -0 be ignored by JSON.stringify, and avoid it return non-string (undefined) before replacing', () => { + expect(dataToEsm([-0, '\u2028\u2029', undefined, function () {}], { compact: true })).toBe( 'export default[-0,"\\u2028\\u2029",undefined,undefined];' ); }); -test('support arbitrary module namespace identifier names', (t) => { - t.is( +test('support arbitrary module namespace identifier names', () => { + expect( dataToEsm( { foo: 'foo', 'foo.bar': 'foo.bar', '\udfff': 'non wellformed' }, { namedExports: true, includeArbitraryNames: true } - ), + ) + ).toBe( 'export var foo = "foo";\nvar _arbitrary0 = "foo.bar";\nexport {\n\t_arbitrary0 as "foo.bar"\n};\nexport default {\n\tfoo: foo,\n\t"foo.bar": "foo.bar",\n\t"\\udfff": "non wellformed"\n};\n' ); - t.is( + expect( dataToEsm( { foo: 'foo', 'foo.bar': 'foo.bar', '\udfff': 'non wellformed' }, { namedExports: true, includeArbitraryNames: true, compact: true } - ), + ) + ).toBe( 'export var foo="foo";var _arbitrary0="foo.bar";export{_arbitrary0 as "foo.bar"};export default{foo:foo,"foo.bar":"foo.bar","\\udfff":"non wellformed"};' ); }); diff --git a/packages/pluginutils/test/extractAssignedNames.ts b/packages/pluginutils/test/extractAssignedNames.ts index 090906eb5..120dd1d8c 100755 --- a/packages/pluginutils/test/extractAssignedNames.ts +++ b/packages/pluginutils/test/extractAssignedNames.ts @@ -1,8 +1,6 @@ -import test from 'ava'; - import { extractAssignedNames } from '../'; -test('extracts an Identifier', (t) => { +test('extracts an Identifier', () => { const node = { type: 'Identifier', start: 6, @@ -10,10 +8,10 @@ test('extracts an Identifier', (t) => { name: 'x' }; - t.deepEqual(extractAssignedNames(node), ['x']); + expect(extractAssignedNames(node)).toEqual(['x']); }); -test('extracts from array patterns', (t) => { +test('extracts from array patterns', () => { const node = { type: 'ArrayPattern', start: 6, @@ -70,10 +68,10 @@ test('extracts from array patterns', (t) => { ] }; - t.deepEqual(extractAssignedNames(node), ['a', 'b', 'd', 'e']); + expect(extractAssignedNames(node)).toEqual(['a', 'b', 'd', 'e']); }); -test('extracts from object patterns', (t) => { +test('extracts from object patterns', () => { const node = { type: 'ObjectPattern', start: 6, @@ -211,10 +209,10 @@ test('extracts from object patterns', (t) => { ] }; - t.deepEqual(extractAssignedNames(node), ['a', 'c', 'f', 'h', 'i']); + expect(extractAssignedNames(node)).toEqual(['a', 'c', 'f', 'h', 'i']); }); -test('ignores updated member expressions', (t) => { +test('ignores updated member expressions', () => { const node = { type: 'ArrayPattern', start: 0, @@ -259,5 +257,5 @@ test('ignores updated member expressions', (t) => { ] }; - t.deepEqual(extractAssignedNames(node), []); + expect(extractAssignedNames(node)).toEqual([]); }); diff --git a/packages/pluginutils/test/filterUtils.ts b/packages/pluginutils/test/filterUtils.ts index 2a3c98750..fe55acb1d 100644 --- a/packages/pluginutils/test/filterUtils.ts +++ b/packages/pluginutils/test/filterUtils.ts @@ -1,75 +1,73 @@ -import test from 'ava'; - import { exactRegex, prefixRegex, suffixRegex } from '../'; -test('exactRegex supports without flag parameter', (t) => { - t.is(exactRegex('foo').toString(), '/^foo$/'); +test('exactRegex supports without flag parameter', () => { + expect(exactRegex('foo').toString()).toBe('/^foo$/'); }); -test('exactRegex supports with multiple string and without flag parameter', (t) => { - t.is(exactRegex(['foo', 'bar']).toString(), '/^(?:foo|bar)$/'); +test('exactRegex supports with multiple string and without flag parameter', () => { + expect(exactRegex(['foo', 'bar']).toString()).toBe('/^(?:foo|bar)$/'); }); -test('exactRegex supports with flag parameter', (t) => { - t.is(exactRegex('foo', 'i').toString(), '/^foo$/i'); +test('exactRegex supports with flag parameter', () => { + expect(exactRegex('foo', 'i').toString()).toBe('/^foo$/i'); }); -test('exactRegex supports with multiple string and flag parameter', (t) => { - t.is(exactRegex(['foo', 'bar'], 'i').toString(), '/^(?:foo|bar)$/i'); +test('exactRegex supports with multiple string and flag parameter', () => { + expect(exactRegex(['foo', 'bar'], 'i').toString()).toBe('/^(?:foo|bar)$/i'); }); -test('exactRegex escapes special characters for Regex', (t) => { - t.is(exactRegex('foo(bar)').toString(), '/^foo\\(bar\\)$/'); +test('exactRegex escapes special characters for Regex', () => { + expect(exactRegex('foo(bar)').toString()).toBe('/^foo\\(bar\\)$/'); }); -test('exactRegex escapes special characters with multiple string for Regex', (t) => { - t.is(exactRegex(['foo(bar)', 'baz(qux)']).toString(), '/^(?:foo\\(bar\\)|baz\\(qux\\))$/'); +test('exactRegex escapes special characters with multiple string for Regex', () => { + expect(exactRegex(['foo(bar)', 'baz(qux)']).toString()).toBe('/^(?:foo\\(bar\\)|baz\\(qux\\))$/'); }); -test('prefixRegex supports without flag parameter', (t) => { - t.is(prefixRegex('foo').toString(), '/^foo/'); +test('prefixRegex supports without flag parameter', () => { + expect(prefixRegex('foo').toString()).toBe('/^foo/'); }); -test('prefixRegex supports with multiple string and without flag parameter', (t) => { - t.is(prefixRegex(['foo', 'bar']).toString(), '/^(?:foo|bar)/'); +test('prefixRegex supports with multiple string and without flag parameter', () => { + expect(prefixRegex(['foo', 'bar']).toString()).toBe('/^(?:foo|bar)/'); }); -test('prefixRegex supports with flag parameter', (t) => { - t.is(prefixRegex('foo', 'i').toString(), '/^foo/i'); +test('prefixRegex supports with flag parameter', () => { + expect(prefixRegex('foo', 'i').toString()).toBe('/^foo/i'); }); -test('prefixRegex supports with multiple string and flag parameter', (t) => { - t.is(prefixRegex(['foo', 'bar'], 'i').toString(), '/^(?:foo|bar)/i'); +test('prefixRegex supports with multiple string and flag parameter', () => { + expect(prefixRegex(['foo', 'bar'], 'i').toString()).toBe('/^(?:foo|bar)/i'); }); -test('prefixRegex escapes special characters for Regex', (t) => { - t.is(prefixRegex('foo(bar)').toString(), '/^foo\\(bar\\)/'); +test('prefixRegex escapes special characters for Regex', () => { + expect(prefixRegex('foo(bar)').toString()).toBe('/^foo\\(bar\\)/'); }); -test('prefixRegex escapes special characters with multiple string for Regex', (t) => { - t.is(prefixRegex(['foo(bar)', 'baz(qux)']).toString(), '/^(?:foo\\(bar\\)|baz\\(qux\\))/'); +test('prefixRegex escapes special characters with multiple string for Regex', () => { + expect(prefixRegex(['foo(bar)', 'baz(qux)']).toString()).toBe('/^(?:foo\\(bar\\)|baz\\(qux\\))/'); }); -test('suffixRegex supports without flag parameter', (t) => { - t.is(suffixRegex('foo').toString(), '/foo$/'); +test('suffixRegex supports without flag parameter', () => { + expect(suffixRegex('foo').toString()).toBe('/foo$/'); }); -test('suffixRegex supports with multiple string and without flag parameter', (t) => { - t.is(suffixRegex(['foo', 'bar']).toString(), '/(?:foo|bar)$/'); +test('suffixRegex supports with multiple string and without flag parameter', () => { + expect(suffixRegex(['foo', 'bar']).toString()).toBe('/(?:foo|bar)$/'); }); -test('suffixRegex supports with flag parameter', (t) => { - t.is(suffixRegex('foo', 'i').toString(), '/foo$/i'); +test('suffixRegex supports with flag parameter', () => { + expect(suffixRegex('foo', 'i').toString()).toBe('/foo$/i'); }); -test('suffixRegex supports with multiple string and flag parameter', (t) => { - t.is(suffixRegex(['foo', 'bar'], 'i').toString(), '/(?:foo|bar)$/i'); +test('suffixRegex supports with multiple string and flag parameter', () => { + expect(suffixRegex(['foo', 'bar'], 'i').toString()).toBe('/(?:foo|bar)$/i'); }); -test('suffixRegex escapes special characters for Regex', (t) => { - t.is(suffixRegex('foo(bar)').toString(), '/foo\\(bar\\)$/'); +test('suffixRegex escapes special characters for Regex', () => { + expect(suffixRegex('foo(bar)').toString()).toBe('/foo\\(bar\\)$/'); }); -test('suffixRegex escapes special characters with multiple string for Regex', (t) => { - t.is(suffixRegex(['foo(bar)', 'baz(qux)']).toString(), '/(?:foo\\(bar\\)|baz\\(qux\\))$/'); +test('suffixRegex escapes special characters with multiple string for Regex', () => { + expect(suffixRegex(['foo(bar)', 'baz(qux)']).toString()).toBe('/(?:foo\\(bar\\)|baz\\(qux\\))$/'); }); diff --git a/packages/pluginutils/test/makeLegalIdentifier.ts b/packages/pluginutils/test/makeLegalIdentifier.ts index 2d8ef45fb..665a21542 100755 --- a/packages/pluginutils/test/makeLegalIdentifier.ts +++ b/packages/pluginutils/test/makeLegalIdentifier.ts @@ -1,23 +1,21 @@ -import test from 'ava'; - import { makeLegalIdentifier } from '../'; -test('camel-cases names', (t) => { - t.is(makeLegalIdentifier('foo-bar'), 'fooBar'); +test('camel-cases names', () => { + expect(makeLegalIdentifier('foo-bar')).toBe('fooBar'); }); -test('replaces keywords', (t) => { - t.is(makeLegalIdentifier('typeof'), '_typeof'); +test('replaces keywords', () => { + expect(makeLegalIdentifier('typeof')).toBe('_typeof'); }); -test('blacklists arguments (https://github.com/rollup/rollup/issues/871)', (t) => { - t.is(makeLegalIdentifier('arguments'), '_arguments'); +test('blacklists arguments (https://github.com/rollup/rollup/issues/871)', () => { + expect(makeLegalIdentifier('arguments')).toBe('_arguments'); }); -test('empty', (t) => { - t.is(makeLegalIdentifier(''), '_'); +test('empty', () => { + expect(makeLegalIdentifier('')).toBe('_'); }); -test('handles input evaluated to blacklisted identifier', (t) => { - t.is(makeLegalIdentifier('parse-int'), '_parseInt'); +test('handles input evaluated to blacklisted identifier', () => { + expect(makeLegalIdentifier('parse-int')).toBe('_parseInt'); }); diff --git a/packages/pluginutils/test/normalizePath.ts b/packages/pluginutils/test/normalizePath.ts index 06c9914c5..a0e50ed68 100644 --- a/packages/pluginutils/test/normalizePath.ts +++ b/packages/pluginutils/test/normalizePath.ts @@ -1,17 +1,15 @@ -import test from 'ava'; - import { normalizePath } from '../'; -test('replaces \\ with /', (t) => { - t.is(normalizePath('foo\\bar'), 'foo/bar'); - t.is(normalizePath('foo\\bar\\baz'), 'foo/bar/baz'); +test('replaces \\ with /', () => { + expect(normalizePath('foo\\bar')).toBe('foo/bar'); + expect(normalizePath('foo\\bar\\baz')).toBe('foo/bar/baz'); }); -test('ignores forward slash', (t) => { - t.is(normalizePath('foo/bar'), 'foo/bar'); - t.is(normalizePath('foo/bar\\baz'), 'foo/bar/baz'); +test('ignores forward slash', () => { + expect(normalizePath('foo/bar')).toBe('foo/bar'); + expect(normalizePath('foo/bar\\baz')).toBe('foo/bar/baz'); }); -test('handles empty string', (t) => { - t.is(normalizePath(''), ''); +test('handles empty string', () => { + expect(normalizePath('')).toBe(''); }); diff --git a/packages/run/package.json b/packages/run/package.json index 134d04d24..b804b5af6 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -28,13 +28,13 @@ "ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov", "ci:lint": "pnpm build && pnpm lint", "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", - "ci:test": "pnpm test -- --verbose", + "ci:test": "pnpm test -- --reporter=verbose", "prebuild": "del-cli dist", "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", "release": "pnpm --workspace-root package:release $(pwd)", - "test": "ava" + "test": "vitest --config ../../.config/vitest.config.mts run" }, "files": [ "dist", @@ -67,15 +67,5 @@ "sinon": "^14.0.0", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", - "ava": { - "workerThreads": false, - "files": [ - "!**/fixtures/**", - "!**/output/**", - "!**/helpers/**", - "!**/recipes/**", - "!**/types.ts" - ] - } + "types": "./types/index.d.ts" } diff --git a/packages/run/test/test.js b/packages/run/test/test.js index 587850433..ae53e16c4 100644 --- a/packages/run/test/test.js +++ b/packages/run/test/test.js @@ -9,7 +9,6 @@ const writeFile = require('util').promisify(fs.writeFile); const del = require('del'); const { rollup } = require('rollup'); -const test = require('ava'); const sinon = require('sinon'); const run = require('../'); @@ -25,22 +24,22 @@ const outputOptions = { file, format: 'cjs' }; const outputDirOptions = { dir: outputDir, format: 'cjs' }; let mockChildProcess; -test.before(() => { +beforeAll(() => { mockChildProcess = sinon .stub(childProcess, ['fork']) .returns({ ...new EventEmitter(), kill: sinon.fake() }); }); -test('builds the bundle and forks a child process', async (t) => { +test('builds the bundle and forks a child process', async () => { const bundle = await rollup({ input, plugins: [run()] }); await bundle.write(outputOptions); - t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); + expect(mockChildProcess.calledWithExactly(outputOptions.file, [], {})).toBe(true); }); -test('takes input from the latest options', async (t) => { +test('takes input from the latest options', async () => { const bundle = await rollup({ input: 'incorrect', plugins: [ @@ -55,20 +54,20 @@ test('takes input from the latest options', async (t) => { ] }); await bundle.write(outputOptions); - t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); + expect(mockChildProcess.calledWithExactly(outputOptions.file, [], {})).toBe(true); }); -test('checks entry point facade module', async (t) => { +test('checks entry point facade module', async () => { const bundle = await rollup({ input: join(cwd, 'facade-entry/index.js'), preserveEntrySignatures: 'strict', plugins: [run()] }); await bundle.write(outputDirOptions); - t.true(mockChildProcess.calledWithExactly(join(outputDir, 'index.js'), [], {})); + expect(mockChildProcess.calledWithExactly(join(outputDir, 'index.js'), [], {})).toBe(true); }); -test('allows pass-through options for child_process.fork', async (t) => { +test('allows pass-through options for child_process.fork', async () => { const forkOptions = { cwd, detached: false, @@ -79,60 +78,51 @@ test('allows pass-through options for child_process.fork', async (t) => { plugins: [run(forkOptions)] }); await bundle.write(outputOptions); - t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], forkOptions)); + expect(mockChildProcess.calledWithExactly(outputOptions.file, [], forkOptions)).toBe(true); }); -test('throws an error when bundle is not written to disk', async (t) => { +test('throws an error when bundle is not written to disk', async () => { const bundle = await rollup({ input, plugins: [run()] }); - await t.throwsAsync( - async () => { - await bundle.generate(outputOptions); - }, - { - instanceOf: Error, - message: '@rollup/plugin-run currently only works with bundles that are written to disk' - } + + const error = await bundle.generate(outputOptions).catch((caught) => caught); + + expect(error).toBeInstanceOf(Error); + expect(error.message).toBe( + '@rollup/plugin-run currently only works with bundles that are written to disk' ); }); -test('throws an error when input option is invalid', async (t) => { +test('throws an error when input option is invalid', async () => { const testInput = join(cwd, 'change-detect-input.js'); const bundle = await rollup({ input: [input, testInput], plugins: [run({ input: 'something that is not an input' })] }); - await t.throwsAsync( - async () => { - await bundle.write(outputDirOptions); - }, - { - instanceOf: Error, - message: '@rollup/plugin-run could not find output chunk' - } - ); + + const error = await bundle.write(outputDirOptions).catch((caught) => caught); + + expect(error).toBeInstanceOf(Error); + expect(error.message).toBe('@rollup/plugin-run could not find output chunk'); }); -test('throws an error when there are multiple entry points', async (t) => { +test('throws an error when there are multiple entry points', async () => { const testInput = join(cwd, 'change-detect-input.js'); - await t.throwsAsync( - async () => { - await rollup({ - input: [input, testInput], - plugins: [run()] - }); - }, - { - instanceOf: Error, - message: - '@rollup/plugin-run must have a single entry point; consider setting the `input` option' - } + + const error = await rollup({ + input: [input, testInput], + plugins: [run()] + }).catch((caught) => caught); + + expect(error).toBeInstanceOf(Error); + expect(error.message).toBe( + '@rollup/plugin-run must have a single entry point; consider setting the `input` option' ); }); -test('detects changes - forks a new child process and kills older process', async (t) => { +test('detects changes - forks a new child process and kills older process', async () => { // eslint-disable-next-line no-shadow const testInput = join(cwd, 'change-detect-input.js'); const bundle = await rollup({ @@ -142,29 +132,29 @@ test('detects changes - forks a new child process and kills older process', asyn await bundle.write(outputOptions); await writeFile(testInput, "export const Greeting = () => 'Hola'; // eslint-disable-line"); await bundle.write(outputOptions); - t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); - t.is(mockChildProcess().kill.callCount, 1); + expect(mockChildProcess.calledWithExactly(outputOptions.file, [], {})).toBe(true); + expect(mockChildProcess().kill.callCount).toBe(1); }); -test('allow the allowRestart option', async (t) => { +test('allow the allowRestart option', async () => { const bundle = await rollup({ input, plugins: [run({ allowRestarts: true })] }); await bundle.write(outputOptions); - t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); + expect(mockChildProcess.calledWithExactly(outputOptions.file, [], {})).toBe(true); }); -test('allow the input option', async (t) => { +test('allow the input option', async () => { const testInput = join(cwd, 'change-detect-input.js'); const bundle = await rollup({ input: [input, testInput], plugins: [run({ input })] }); await bundle.write(outputDirOptions); - t.true(mockChildProcess.calledWithExactly(join(outputDir, 'input.js'), [], { input })); + expect(mockChildProcess.calledWithExactly(join(outputDir, 'input.js'), [], { input })).toBe(true); }); -test.after(async () => { +afterAll(async () => { await del(['output']); });