Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: enable typecheck for _config files #4954

Merged
merged 17 commits into from May 1, 2023
Merged
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .eslintrc.js
Expand Up @@ -66,6 +66,12 @@ module.exports = {
'no-undef': 'off',
'unicorn/prevent-abbreviations': 'off'
}
},
{
files: ['test/**/_config.js'],
rules: {
'no-undef': 'off'
}
}
],
parser: '@typescript-eslint/parser',
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Expand Up @@ -4,5 +4,7 @@
"typescript.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"references.preferredLocation": "peek",
"vue.features.codeActions.enable": false
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -81,6 +81,7 @@
"@rollup/plugin-typescript": "^11.0.0",
"@rollup/pluginutils": "^5.0.2",
"@types/estree": "1.0.0",
"@types/mocha": "^10.0.1",
"@types/node": "^14.18.36",
"@types/signal-exit": "^3.0.1",
"@types/yargs-parser": "^21.0.0",
Expand Down
5 changes: 5 additions & 0 deletions test/browser/define.d.ts
@@ -0,0 +1,5 @@
import type { TestConfigBase } from '../types';

declare global {
function defineTest(config: TestConfigBase): TestConfigBase;
}
6 changes: 6 additions & 0 deletions test/browser/index.js
@@ -1,10 +1,16 @@
// since we don't run the browser tests in an actual browser, we need to make `performance`
// globally accessible same as in the browser. this can be removed once `performance` is
// available globally in all supported platforms. [currently global for node.js v16+].
// @ts-expect-error ignore
global.performance = require('node:perf_hooks').performance;

const { basename, resolve } = require('node:path');
const fixturify = require('fixturify');

/**
* @type {import('../../src/rollup/types')} Rollup
*/
// @ts-expect-error cast to Rollup
const { rollup } = require('../../browser/dist/rollup.browser.js');
const { assertFilesAreEqual, runTestSuiteWithSamples, compareError } = require('../utils.js');

Expand Down
4 changes: 2 additions & 2 deletions test/browser/samples/basic/_config.js
@@ -1,6 +1,6 @@
const { loader } = require('../../../utils.js');

module.exports = {
module.exports = defineTest({
description: 'bundles files for the browser',
options: {
plugins: loader({
Expand All @@ -9,4 +9,4 @@ console.log(foo);`,
dep: `export const foo = 42;`
})
}
};
});
4 changes: 2 additions & 2 deletions test/browser/samples/missing-dependency-resolution/_config.js
@@ -1,6 +1,6 @@
const { loader } = require('../../../utils.js');

module.exports = {
module.exports = defineTest({
description: 'fails if a dependency cannot be resolved',
options: {
plugins: loader({
Expand All @@ -15,4 +15,4 @@ console.log(foo);`
url: 'https://rollupjs.org/plugin-development/#a-simple-example',
watchFiles: ['main']
}
};
});
4 changes: 2 additions & 2 deletions test/browser/samples/missing-entry-resolution/_config.js
@@ -1,9 +1,9 @@
module.exports = {
module.exports = defineTest({
description: 'fails if an entry cannot be resolved',
error: {
code: 'NO_FS_IN_BROWSER',
message:
'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.',
url: 'https://rollupjs.org/plugin-development/#a-simple-example'
}
};
});
4 changes: 2 additions & 2 deletions test/browser/samples/missing-load/_config.js
@@ -1,4 +1,4 @@
module.exports = {
module.exports = defineTest({
description: 'fails if a file cannot be loaded',
options: {
plugins: {
Expand All @@ -14,4 +14,4 @@ module.exports = {
url: 'https://rollupjs.org/plugin-development/#a-simple-example',
watchFiles: ['main']
}
};
});
5 changes: 3 additions & 2 deletions test/browser/samples/renormalizes-external-paths/_config.js
@@ -1,13 +1,14 @@
const { join, dirname } = require('node:path').posix;

module.exports = {
module.exports = defineTest({
description: 'renormalizes external paths if possible',
options: {
input: ['/main.js', '/nested/entry.js'],
external(id) {
return id.endsWith('ext');
},
plugins: {
name: 'test-plugin',
resolveId(source, importer) {
if (source.endsWith('ext.js')) {
return false;
Expand Down Expand Up @@ -44,4 +45,4 @@ import './nested-ext.js';`;
}
}
}
};
});
4 changes: 2 additions & 2 deletions test/browser/samples/supports-hashes/_config.js
@@ -1,6 +1,6 @@
const { loader } = require('../../../utils.js');

module.exports = {
module.exports = defineTest({
description: 'bundles files for the browser',
options: {
input: ['main', 'dep'],
Expand All @@ -13,4 +13,4 @@ console.log(foo);`,
entryFileNames: '[name]-[hash].js'
}
}
};
});
8 changes: 8 additions & 0 deletions test/browser/tsconfig.json
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.base.json",
"include": [
"**/_config.js",
"./index.js",
"./define.d.ts"
]
}
5 changes: 5 additions & 0 deletions test/chunking-form/define.d.ts
@@ -0,0 +1,5 @@
import type { TestConfigChunkingForm } from '../types';

declare global {
function defineTest(config: TestConfigChunkingForm): TestConfigChunkingForm;
}
6 changes: 6 additions & 0 deletions test/chunking-form/index.js
@@ -1,5 +1,8 @@
const { basename, resolve } = require('node:path');
const { chdir } = require('node:process');
/**
* @type {import('../../src/rollup/types')} Rollup
*/
const { rollup } = require('../../dist/rollup');
const { runTestSuiteWithSamples, assertDirectoriesAreEqual } = require('../utils.js');

Expand Down Expand Up @@ -63,6 +66,7 @@ async function generateAndTestBundle(bundle, outputOptions, expectedDirectory, c
if (outputOptions.format === 'amd' && config.runAmd) {
try {
const exports = await new Promise((resolve, reject) => {
// @ts-expect-error global
global.assert = require('node:assert');
const requirejs = require('requirejs');
requirejs.config({ baseUrl: outputOptions.dir });
Expand All @@ -73,7 +77,9 @@ async function generateAndTestBundle(bundle, outputOptions, expectedDirectory, c
}
} finally {
delete require.cache[require.resolve('requirejs')];
// @ts-expect-error global
delete global.requirejsVars;
// @ts-expect-error global
delete global.assert;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/chunking-form/samples/aliasing-extensions/_config.js
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'chunk aliasing with extensions',
options: {
input: ['main1', 'main2', 'main3.ts']
}
};
});
@@ -1,4 +1,4 @@
module.exports = {
module.exports = defineTest({
description: "allows to use amd.autoId with amd.basePath and works when concat'd into one file",
options: {
input: ['main'],
Expand Down Expand Up @@ -31,4 +31,4 @@ module.exports = {
return exports.getA();
}
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/amd-id-auto-base-path/_config.js
@@ -1,4 +1,4 @@
module.exports = {
module.exports = defineTest({
description: 'allows to use amd.autoId with amd.basePath, and chunks folder',
options: {
input: ['main'],
Expand All @@ -16,4 +16,4 @@ module.exports = {
return exports.getA();
}
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/amd-id-auto/_config.js
@@ -1,4 +1,4 @@
module.exports = {
module.exports = defineTest({
description: 'allows to use amd.autoId',
options: {
input: ['main'],
Expand All @@ -13,4 +13,4 @@ module.exports = {
return exports.getA();
}
}
};
});
@@ -1,6 +1,6 @@
const assert = require('node:assert');

module.exports = {
module.exports = defineTest({
description:
'emits unreferenced assets if needsCodeReference is true if they are also emitted without that flag',
options: {
Expand Down Expand Up @@ -95,4 +95,4 @@ module.exports = {
}
]
}
};
});
Expand Up @@ -2,7 +2,7 @@ const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');

module.exports = {
module.exports = defineTest({
description: 'does not emit unreferenced assets if needsCodeReference is true',
options: {
output: {
Expand Down Expand Up @@ -32,4 +32,4 @@ module.exports = {
}
]
}
};
});
@@ -1,4 +1,4 @@
module.exports = {
module.exports = defineTest({
description: 'avoids hoisting transitive dependencies via flag',
options: {
input: ['main1.js', 'main2.js'],
Expand All @@ -7,4 +7,4 @@ module.exports = {
hoistTransitiveImports: false
}
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/basic-chunking/_config.js
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'simple chunking',
options: {
input: ['main1.js', 'main2.js']
}
};
});
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'chunk reassignment import deshadowing',
options: {
input: ['main1.js', 'main2.js', 'main3.js', 'main4.js']
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/chunk-execution-order/_config.js
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'maintains execution order ',
options: {
input: ['main1.js', 'main2.js', 'main3.js', 'main4.js']
}
};
});
@@ -1,7 +1,7 @@
module.exports = {
module.exports = defineTest({
description: 'chunk export deshadowing',
expectedWarnings: ['CIRCULAR_DEPENDENCY'],
options: {
input: ['main1.js', 'main2.js']
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/chunk-export-renaming/_config.js
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'chunk export renaming',
options: {
input: ['main1.js', 'main2.js']
}
};
});
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'chunk import deshadowing',
options: {
input: ['main1.js', 'main2.js']
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/chunk-live-bindings/_config.js
@@ -1,7 +1,7 @@
module.exports = {
module.exports = defineTest({
description: 'ES module live bindings in chunks',
expectedWarnings: ['CIRCULAR_DEPENDENCY'],
options: {
input: ['main1.js', 'main2.js']
}
};
});
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'chunk with a namespace boundary',
options: {
input: ['main1.js', 'main2.js']
}
};
});
4 changes: 2 additions & 2 deletions test/chunking-form/samples/chunk-naming/_config.js
@@ -1,4 +1,4 @@
module.exports = {
module.exports = defineTest({
description: 'simple chunking',
options: {
input: {
Expand All @@ -10,4 +10,4 @@ module.exports = {
chunkFileNames: 'chunks/chunk.js'
}
}
};
});
@@ -1,6 +1,6 @@
module.exports = {
module.exports = defineTest({
description: 'chunk variable name conflict',
options: {
input: ['main1.js', 'main2.js']
}
};
});