Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .config/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -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}'
],
Expand All @@ -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)
Expand Down
16 changes: 3 additions & 13 deletions packages/auto-install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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"
}
12 changes: 5 additions & 7 deletions packages/auto-install/test/npm-bare.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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: {
Expand All @@ -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']);
});
33 changes: 17 additions & 16 deletions packages/auto-install/test/npm.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -16,27 +15,29 @@ 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: {
file,
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: {
Expand All @@ -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, '{}');
});
10 changes: 4 additions & 6 deletions packages/auto-install/test/pnpm-bare.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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: {
Expand All @@ -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']);
});
10 changes: 4 additions & 6 deletions packages/auto-install/test/pnpm.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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: {
Expand All @@ -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', '');
});
Binary file modified packages/auto-install/test/snapshots/npm-bare.js.snap
Binary file not shown.
Binary file modified packages/auto-install/test/snapshots/npm.js.snap
Binary file not shown.
10 changes: 4 additions & 6 deletions packages/auto-install/test/yarn-bare.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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: {
Expand All @@ -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']);
});
10 changes: 4 additions & 6 deletions packages/auto-install/test/yarn.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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: {
Expand All @@ -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', '');
});
19 changes: 2 additions & 17 deletions packages/pluginutils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 13 additions & 15 deletions packages/pluginutils/test/addExtension.ts
Original file line number Diff line number Diff line change
@@ -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');
});
Loading
Loading