Skip to content

Commit 64870c3

Browse files
antfulukastaegert
andauthored
test: enable typecheck for _config files (#4954)
* chore: init * chore: basic * chore: revert vscode config * chore: fix syntax error * chore: improve typecheck * feat: different types based on dirs * chore: update * chore: update * fix: fix some type error * chore: disable check js for now * chore: update * chore: update * chore: fix emission issue in WebStorm * Fix some type issues * Use correct properties per test type --------- Co-authored-by: Lukas Taegert-Atkinson <[email protected]>
1 parent 4fb9778 commit 64870c3

File tree

1,978 files changed

+4943
-4209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,978 files changed

+4943
-4209
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ module.exports = {
6666
'no-undef': 'off',
6767
'unicorn/prevent-abbreviations': 'off'
6868
}
69+
},
70+
{
71+
files: ['test/**/_config.js'],
72+
rules: {
73+
'no-undef': 'off'
74+
}
6975
}
7076
],
7177
parser: '@typescript-eslint/parser',

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ perf/
1818
.github_token
1919
.temp
2020
docs/.vitepress/graphs
21+
*.tsbuildinfo

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"typescript.format.enable": true,
55
"editor.codeActionsOnSave": {
66
"source.fixAll.eslint": true
7-
}
7+
},
8+
"references.preferredLocation": "peek",
9+
"vue.features.codeActions.enable": false
810
}

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@rollup/plugin-typescript": "^11.1.0",
8282
"@rollup/pluginutils": "^5.0.2",
8383
"@types/estree": "1.0.1",
84+
"@types/mocha": "^10.0.1",
8485
"@types/node": "^14.18.42",
8586
"@types/yargs-parser": "^21.0.0",
8687
"@typescript-eslint/eslint-plugin": "^5.59.1",

src/rollup/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export type InputPluginOption = MaybePromise<Plugin | NullValue | false | InputP
519519

520520
export interface InputOptions {
521521
acorn?: Record<string, unknown>;
522-
acornInjectPlugins?: (() => unknown)[] | (() => unknown);
522+
acornInjectPlugins?: ((...arguments_: any[]) => unknown)[] | ((...arguments_: any[]) => unknown);
523523
cache?: boolean | RollupCache;
524524
context?: string;
525525
experimentalCacheExpiry?: number;

test/browser/define.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { TestConfigBrowser } from '../types';
2+
3+
declare global {
4+
function defineTest(config: TestConfigBrowser): TestConfigBrowser;
5+
}

test/browser/index.js

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,80 @@
11
// since we don't run the browser tests in an actual browser, we need to make `performance`
22
// globally accessible same as in the browser. this can be removed once `performance` is
33
// available globally in all supported platforms. [currently global for node.js v16+].
4+
// @ts-expect-error ignore
45
global.performance = require('node:perf_hooks').performance;
56

67
const { basename, resolve } = require('node:path');
78
const fixturify = require('fixturify');
9+
10+
/**
11+
* @type {import('../../src/rollup/types')} Rollup
12+
*/
813
const { rollup } = require('../../browser/dist/rollup.browser.js');
914
const { assertFilesAreEqual, runTestSuiteWithSamples, compareError } = require('../utils.js');
1015

11-
runTestSuiteWithSamples('browser', resolve(__dirname, 'samples'), (directory, config) => {
12-
(config.skip ? it.skip : config.solo ? it.only : it)(
13-
basename(directory) + ': ' + config.description,
14-
async () => {
15-
let bundle;
16-
try {
17-
bundle = await rollup({
18-
input: 'main',
19-
onwarn: warning => {
20-
if (!(config.expectedWarnings && config.expectedWarnings.includes(warning.code))) {
21-
throw new Error(
22-
`Unexpected warnings (${warning.code}): ${warning.message}\n` +
23-
'If you expect warnings, list their codes in config.expectedWarnings'
24-
);
25-
}
26-
},
27-
strictDeprecations: true,
28-
...config.options
29-
});
30-
} catch (error) {
16+
runTestSuiteWithSamples(
17+
'browser',
18+
resolve(__dirname, 'samples'),
19+
/**
20+
* @param {import('../types').TestConfigBrowser} config
21+
*/
22+
(directory, config) => {
23+
(config.skip ? it.skip : config.solo ? it.only : it)(
24+
basename(directory) + ': ' + config.description,
25+
async () => {
26+
let bundle;
27+
try {
28+
bundle = await rollup({
29+
input: 'main',
30+
onwarn: warning => {
31+
if (!(config.expectedWarnings && config.expectedWarnings.includes(warning.code))) {
32+
throw new Error(
33+
`Unexpected warnings (${warning.code}): ${warning.message}\n` +
34+
'If you expect warnings, list their codes in config.expectedWarnings'
35+
);
36+
}
37+
},
38+
strictDeprecations: true,
39+
...config.options
40+
});
41+
} catch (error) {
42+
if (config.error) {
43+
compareError(error, config.error);
44+
return;
45+
} else {
46+
throw error;
47+
}
48+
}
3149
if (config.error) {
32-
compareError(error, config.error);
33-
return;
34-
} else {
35-
throw error;
50+
throw new Error('Expected an error while rolling up');
51+
}
52+
let output;
53+
try {
54+
({ output } = await bundle.generate({
55+
exports: 'auto',
56+
format: 'es',
57+
...(config.options || {}).output
58+
}));
59+
} catch (error) {
60+
if (config.generateError) {
61+
compareError(error, config.generateError);
62+
return;
63+
} else {
64+
throw error;
65+
}
3666
}
37-
}
38-
if (config.error) {
39-
throw new Error('Expected an error while rolling up');
40-
}
41-
let output;
42-
try {
43-
({ output } = await bundle.generate({
44-
exports: 'auto',
45-
format: 'es',
46-
...(config.options || {}).output
47-
}));
48-
} catch (error) {
4967
if (config.generateError) {
50-
compareError(error, config.generateError);
51-
return;
52-
} else {
53-
throw error;
68+
throw new Error('Expected an error while generating output');
5469
}
70+
assertOutputMatches(output, directory);
5571
}
56-
if (config.generateError) {
57-
throw new Error('Expected an error while generating output');
58-
}
59-
assertOutputMatches(output, directory);
60-
}
61-
);
62-
});
72+
);
73+
}
74+
);
6375

6476
function assertOutputMatches(output, directory) {
77+
/** @type any */
6578
const actual = {};
6679
for (const file of output) {
6780
const filePath = file.fileName.split('/');

test/browser/samples/basic/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { loader } = require('../../../utils.js');
22

3-
module.exports = {
3+
module.exports = defineTest({
44
description: 'bundles files for the browser',
55
options: {
66
plugins: loader({
@@ -9,4 +9,4 @@ console.log(foo);`,
99
dep: `export const foo = 42;`
1010
})
1111
}
12-
};
12+
});

test/browser/samples/missing-dependency-resolution/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { loader } = require('../../../utils.js');
22

3-
module.exports = {
3+
module.exports = defineTest({
44
description: 'fails if a dependency cannot be resolved',
55
options: {
66
plugins: loader({
@@ -15,4 +15,4 @@ console.log(foo);`
1515
url: 'https://rollupjs.org/plugin-development/#a-simple-example',
1616
watchFiles: ['main']
1717
}
18-
};
18+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
module.exports = {
1+
module.exports = defineTest({
22
description: 'fails if an entry cannot be resolved',
33
error: {
44
code: 'NO_FS_IN_BROWSER',
55
message:
66
'Cannot access the file system (via "path.resolve") when using the browser build of Rollup. Make sure you supply a plugin with custom resolveId and load hooks to Rollup.',
77
url: 'https://rollupjs.org/plugin-development/#a-simple-example'
88
}
9-
};
9+
});

test/browser/samples/missing-load/_config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
module.exports = {
1+
module.exports = defineTest({
22
description: 'fails if a file cannot be loaded',
33
options: {
44
plugins: {
5+
name: 'test',
56
resolveId(source) {
67
return source;
78
}
@@ -14,4 +15,4 @@ module.exports = {
1415
url: 'https://rollupjs.org/plugin-development/#a-simple-example',
1516
watchFiles: ['main']
1617
}
17-
};
18+
});

test/browser/samples/renormalizes-external-paths/_config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const { join, dirname } = require('node:path').posix;
22

3-
module.exports = {
3+
module.exports = defineTest({
44
description: 'renormalizes external paths if possible',
55
options: {
66
input: ['/main.js', '/nested/entry.js'],
77
external(id) {
88
return id.endsWith('ext');
99
},
1010
plugins: {
11+
name: 'test-plugin',
1112
resolveId(source, importer) {
1213
if (source.endsWith('ext.js')) {
1314
return false;
@@ -44,4 +45,4 @@ import './nested-ext.js';`;
4445
}
4546
}
4647
}
47-
};
48+
});

test/browser/samples/supports-hashes/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { loader } = require('../../../utils.js');
22

3-
module.exports = {
3+
module.exports = defineTest({
44
description: 'bundles files for the browser',
55
options: {
66
input: ['main', 'dep'],
@@ -13,4 +13,4 @@ console.log(foo);`,
1313
entryFileNames: '[name]-[hash].js'
1414
}
1515
}
16-
};
16+
});

test/browser/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"include": [
4+
"**/_config.js",
5+
"./index.js",
6+
"./define.d.ts"
7+
]
8+
}

test/chunking-form/define.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { TestConfigChunkingForm } from '../types';
2+
3+
declare global {
4+
function defineTest(config: TestConfigChunkingForm): TestConfigChunkingForm;
5+
}

test/chunking-form/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const { basename, resolve } = require('node:path');
22
const { chdir } = require('node:process');
3+
/**
4+
* @type {import('../../src/rollup/types')} Rollup
5+
*/
36
const { rollup } = require('../../dist/rollup');
47
const { runTestSuiteWithSamples, assertDirectoriesAreEqual } = require('../utils.js');
58

@@ -63,6 +66,7 @@ async function generateAndTestBundle(bundle, outputOptions, expectedDirectory, c
6366
if (outputOptions.format === 'amd' && config.runAmd) {
6467
try {
6568
const exports = await new Promise((resolve, reject) => {
69+
// @ts-expect-error global
6670
global.assert = require('node:assert');
6771
const requirejs = require('requirejs');
6872
requirejs.config({ baseUrl: outputOptions.dir });
@@ -73,7 +77,9 @@ async function generateAndTestBundle(bundle, outputOptions, expectedDirectory, c
7377
}
7478
} finally {
7579
delete require.cache[require.resolve('requirejs')];
80+
// @ts-expect-error global
7681
delete global.requirejsVars;
82+
// @ts-expect-error global
7783
delete global.assert;
7884
}
7985
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module.exports = {
1+
module.exports = defineTest({
22
description: 'chunk aliasing with extensions',
33
options: {
44
input: ['main1', 'main2', 'main3.ts']
55
}
6-
};
6+
});

test/chunking-form/samples/amd-id-auto-base-path-concat/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
module.exports = defineTest({
22
description: "allows to use amd.autoId with amd.basePath and works when concat'd into one file",
33
options: {
44
input: ['main'],
@@ -31,4 +31,4 @@ module.exports = {
3131
return exports.getA();
3232
}
3333
}
34-
};
34+
});

test/chunking-form/samples/amd-id-auto-base-path/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
module.exports = defineTest({
22
description: 'allows to use amd.autoId with amd.basePath, and chunks folder',
33
options: {
44
input: ['main'],
@@ -16,4 +16,4 @@ module.exports = {
1616
return exports.getA();
1717
}
1818
}
19-
};
19+
});

test/chunking-form/samples/amd-id-auto/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
module.exports = defineTest({
22
description: 'allows to use amd.autoId',
33
options: {
44
input: ['main'],
@@ -13,4 +13,4 @@ module.exports = {
1313
return exports.getA();
1414
}
1515
}
16-
};
16+
});

0 commit comments

Comments
 (0)