diff --git a/test/browser/define.d.ts b/test/browser/define.d.ts index 1e9efb55b8a..1fde8f77e5e 100644 --- a/test/browser/define.d.ts +++ b/test/browser/define.d.ts @@ -1,5 +1,5 @@ -import type { TestConfigBase } from '../types'; +import type { TestConfigBrowser } from '../types'; declare global { - function defineTest(config: TestConfigBase): TestConfigBase; + function defineTest(config: TestConfigBrowser): TestConfigBrowser; } diff --git a/test/browser/index.js b/test/browser/index.js index f018571a648..2167a4210a9 100644 --- a/test/browser/index.js +++ b/test/browser/index.js @@ -13,58 +13,65 @@ const fixturify = require('fixturify'); const { rollup } = require('../../browser/dist/rollup.browser.js'); const { assertFilesAreEqual, runTestSuiteWithSamples, compareError } = require('../utils.js'); -runTestSuiteWithSamples('browser', resolve(__dirname, 'samples'), (directory, config) => { - (config.skip ? it.skip : config.solo ? it.only : it)( - basename(directory) + ': ' + config.description, - async () => { - let bundle; - try { - bundle = await rollup({ - input: 'main', - onwarn: warning => { - if (!(config.expectedWarnings && config.expectedWarnings.includes(warning.code))) { - throw new Error( - `Unexpected warnings (${warning.code}): ${warning.message}\n` + - 'If you expect warnings, list their codes in config.expectedWarnings' - ); - } - }, - strictDeprecations: true, - ...config.options - }); - } catch (error) { +runTestSuiteWithSamples( + 'browser', + resolve(__dirname, 'samples'), + /** + * @param {import('../types').TestConfigBrowser} config + */ + (directory, config) => { + (config.skip ? it.skip : config.solo ? it.only : it)( + basename(directory) + ': ' + config.description, + async () => { + let bundle; + try { + bundle = await rollup({ + input: 'main', + onwarn: warning => { + if (!(config.expectedWarnings && config.expectedWarnings.includes(warning.code))) { + throw new Error( + `Unexpected warnings (${warning.code}): ${warning.message}\n` + + 'If you expect warnings, list their codes in config.expectedWarnings' + ); + } + }, + strictDeprecations: true, + ...config.options + }); + } catch (error) { + if (config.error) { + compareError(error, config.error); + return; + } else { + throw error; + } + } if (config.error) { - compareError(error, config.error); - return; - } else { - throw error; + throw new Error('Expected an error while rolling up'); + } + let output; + try { + ({ output } = await bundle.generate({ + exports: 'auto', + format: 'es', + ...(config.options || {}).output + })); + } catch (error) { + if (config.generateError) { + compareError(error, config.generateError); + return; + } else { + throw error; + } } - } - if (config.error) { - throw new Error('Expected an error while rolling up'); - } - let output; - try { - ({ output } = await bundle.generate({ - exports: 'auto', - format: 'es', - ...(config.options || {}).output - })); - } catch (error) { if (config.generateError) { - compareError(error, config.generateError); - return; - } else { - throw error; + throw new Error('Expected an error while generating output'); } + assertOutputMatches(output, directory); } - if (config.generateError) { - throw new Error('Expected an error while generating output'); - } - assertOutputMatches(output, directory); - } - ); -}); + ); + } +); function assertOutputMatches(output, directory) { /** @type any */ diff --git a/test/chunking-form/index.js b/test/chunking-form/index.js index f0dd86fcd40..d26628eef97 100644 --- a/test/chunking-form/index.js +++ b/test/chunking-form/index.js @@ -8,55 +8,64 @@ const { runTestSuiteWithSamples, assertDirectoriesAreEqual } = require('../utils const FORMATS = ['es', 'cjs', 'amd', 'system']; -runTestSuiteWithSamples('chunking form', resolve(__dirname, 'samples'), (directory, config) => { - (config.skip ? describe.skip : config.solo ? describe.only : describe)( - basename(directory) + ': ' + config.description, - () => { - let bundle; +runTestSuiteWithSamples( + 'chunking form', + resolve(__dirname, 'samples'), + /** + * @param {import('../types').TestConfigChunkingForm} config + */ + (directory, config) => { + (config.skip ? describe.skip : config.solo ? describe.only : describe)( + basename(directory) + ': ' + config.description, + async () => { + let bundle; - if (config.before) { - before(config.before); - } - if (config.after) { - after(config.after); - } + if (config.before) { + await before(config.before); + } + if (config.after) { + await after(config.after); + } - for (const format of FORMATS) { - it('generates ' + format, async () => { - chdir(directory); - bundle = - bundle || - (await rollup({ - input: [directory + '/main.js'], - onwarn: warning => { - if (!(config.expectedWarnings && config.expectedWarnings.includes(warning.code))) { - throw new Error( - `Unexpected warnings (${warning.code}): ${warning.message}\n` + - 'If you expect warnings, list their codes in config.expectedWarnings' - ); - } + for (const format of FORMATS) { + it('generates ' + format, async () => { + chdir(directory); + bundle = + bundle || + (await rollup({ + input: [directory + '/main.js'], + onwarn: warning => { + if ( + !(config.expectedWarnings && config.expectedWarnings.includes(warning.code)) + ) { + throw new Error( + `Unexpected warnings (${warning.code}): ${warning.message}\n` + + 'If you expect warnings, list their codes in config.expectedWarnings' + ); + } + }, + strictDeprecations: true, + ...config.options + })); + await generateAndTestBundle( + bundle, + { + dir: `${directory}/_actual/${format}`, + exports: 'auto', + format, + chunkFileNames: 'generated-[name].js', + validate: true, + ...(config.options || {}).output }, - strictDeprecations: true, - ...config.options - })); - await generateAndTestBundle( - bundle, - { - dir: `${directory}/_actual/${format}`, - exports: 'auto', - format, - chunkFileNames: 'generated-[name].js', - validate: true, - ...(config.options || {}).output - }, - `${directory}/_expected/${format}`, - config - ); - }); + `${directory}/_expected/${format}`, + config + ); + }); + } } - } - ); -}); + ); + } +); async function generateAndTestBundle(bundle, outputOptions, expectedDirectory, config) { await bundle.write({ diff --git a/test/chunking-form/samples/deprecated/empty-module-no-treeshake/_config.js b/test/chunking-form/samples/deprecated/empty-module-no-treeshake/_config.js index 3fa8b308782..bd12a97ad57 100644 --- a/test/chunking-form/samples/deprecated/empty-module-no-treeshake/_config.js +++ b/test/chunking-form/samples/deprecated/empty-module-no-treeshake/_config.js @@ -1,5 +1,6 @@ const assert = require('node:assert'); const path = require('node:path'); +// @ts-expect-error not included in types const { getObject } = require('../../../../utils'); module.exports = defineTest({ diff --git a/test/cli/index.js b/test/cli/index.js index 02f667cabde..d287bfd3684 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -57,8 +57,10 @@ async function runTest(config, command) { env: { ...process.env, FORCE_COLOR: '0', ...config.env }, killSignal: 'SIGKILL' }, - (error, code, stderr) => { - if (config.after) config.after(error, code, stderr); + async (error, code, stderr) => { + if (config.after) { + await config.after(error, code, stderr); + } if (error && !error.killed) { if (config.error) { if (!config.error(error)) { @@ -94,7 +96,7 @@ async function runTest(config, command) { } if (config.exports) { - config.exports(module.exports); + await config.exports(module.exports); } } catch (error) { if (config.error) { diff --git a/test/cli/samples/config-type-module/_config.js b/test/cli/samples/config-type-module/_config.js index f586b2ac67f..772593d9d2a 100644 --- a/test/cli/samples/config-type-module/_config.js +++ b/test/cli/samples/config-type-module/_config.js @@ -1,3 +1,4 @@ +// @ts-expect-error not included in types const { assertIncludes } = require('../../../utils.js'); module.exports = defineTest({ diff --git a/test/file-hashes/index.js b/test/file-hashes/index.js index 74e5ed61446..360b6396cfb 100644 --- a/test/file-hashes/index.js +++ b/test/file-hashes/index.js @@ -2,7 +2,9 @@ const path = require('node:path'); /** * @type {import('../../src/rollup/types')} Rollup */ +// @ts-expect-error not included in types const rollup = require('../../dist/rollup'); +// @ts-expect-error not included in types const { runTestSuiteWithSamples } = require('../utils.js'); runTestSuiteWithSamples( diff --git a/test/form/index.js b/test/form/index.js index 1761eb74b56..e45c7e1aa90 100644 --- a/test/form/index.js +++ b/test/form/index.js @@ -4,78 +4,92 @@ const { basename, resolve } = require('node:path'); /** * @type {import('../../src/rollup/types')} Rollup */ +// @ts-expect-error not included in types const { rollup } = require('../../dist/rollup'); const { normaliseOutput, runTestSuiteWithSamples } = require('../utils.js'); const FORMATS = ['amd', 'cjs', 'system', 'es', 'iife', 'umd']; -runTestSuiteWithSamples('form', resolve(__dirname, 'samples'), (directory, config) => { - const isSingleFormatTest = existsSync(directory + '/_expected.js'); - const itOrDescribe = isSingleFormatTest ? it : describe; - (config.skip ? itOrDescribe.skip : config.solo ? itOrDescribe.only : itOrDescribe)( - basename(directory) + ': ' + config.description, - () => { - let bundle; - const runRollupTest = async (inputFile, bundleFile, defaultFormat) => { - const warnings = []; - if (config.before) config.before(); - try { - process.chdir(directory); - bundle = - bundle || - (await rollup({ - input: directory + '/main.js', - onwarn: warning => { - if (!(config.expectedWarnings && config.expectedWarnings.includes(warning.code))) { - warnings.push(warning); - } +runTestSuiteWithSamples( + 'form', + resolve(__dirname, 'samples'), + /** + * @param {import('../types').TestConfigForm} config + */ + (directory, config) => { + const isSingleFormatTest = existsSync(directory + '/_expected.js'); + const itOrDescribe = isSingleFormatTest ? it : describe; + (config.skip ? itOrDescribe.skip : config.solo ? itOrDescribe.only : itOrDescribe)( + basename(directory) + ': ' + config.description, + () => { + let bundle; + const runRollupTest = async (inputFile, bundleFile, defaultFormat) => { + const warnings = []; + if (config.before) { + await config.before(); + } + try { + process.chdir(directory); + bundle = + bundle || + (await rollup({ + input: directory + '/main.js', + onwarn: warning => { + if ( + !(config.expectedWarnings && config.expectedWarnings.includes(warning.code)) + ) { + warnings.push(warning); + } + }, + strictDeprecations: true, + ...config.options + })); + await generateAndTestBundle( + bundle, + { + exports: 'auto', + file: inputFile, + format: defaultFormat, + validate: true, + ...(config.options || {}).output }, - strictDeprecations: true, - ...config.options - })); - await generateAndTestBundle( - bundle, - { - exports: 'auto', - file: inputFile, - format: defaultFormat, - validate: true, - ...(config.options || {}).output - }, - bundleFile, - config - ); - } finally { - if (config.after) config.after(); - } - if (warnings.length > 0) { - const codes = new Set(); - for (const { code } of warnings) { - codes.add(code); + bundleFile, + config + ); + } finally { + if (config.after) { + await config.after(); + } } - throw new Error( - `Unexpected warnings (${[...codes].join(', ')}): \n${warnings - .map(({ message }) => `${message}\n\n`) - .join('')}` + 'If you expect warnings, list their codes in config.expectedWarnings' - ); + if (warnings.length > 0) { + const codes = new Set(); + for (const { code } of warnings) { + codes.add(code); + } + throw new Error( + `Unexpected warnings (${[...codes].join(', ')}): \n${warnings + .map(({ message }) => `${message}\n\n`) + .join('')}` + 'If you expect warnings, list their codes in config.expectedWarnings' + ); + } + }; + + if (isSingleFormatTest) { + return runRollupTest(directory + '/_actual.js', directory + '/_expected.js', 'es'); } - }; - if (isSingleFormatTest) { - return runRollupTest(directory + '/_actual.js', directory + '/_expected.js', 'es'); + for (const format of config.formats || FORMATS) + it('generates ' + format, () => + runRollupTest( + directory + '/_actual/' + format + '.js', + directory + '/_expected/' + format + '.js', + format + ) + ); } - - for (const format of config.formats || FORMATS) - it('generates ' + format, () => - runRollupTest( - directory + '/_actual/' + format + '.js', - directory + '/_expected/' + format + '.js', - format - ) - ); - } - ); -}); + ); + } +); async function generateAndTestBundle(bundle, outputOptions, expectedFile, { show }) { await bundle.write(outputOptions); diff --git a/test/form/samples/addon-functions/_config.js b/test/form/samples/addon-functions/_config.js index b7c5b899b3b..3379a2debf8 100644 --- a/test/form/samples/addon-functions/_config.js +++ b/test/form/samples/addon-functions/_config.js @@ -1,4 +1,5 @@ const assert = require('node:assert'); +// @ts-expect-error not included in types const { replaceDirectoryInStringifiedObject } = require('../../../utils'); const assertChunkData = chunk => assert.strictEqual( diff --git a/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js b/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js index 0d2f5af3c66..6cd9a15555a 100644 --- a/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js +++ b/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js @@ -1,6 +1,6 @@ module.exports = defineTest({ description: 'keep import assertions for dynamic imports', - expectedWarnings: 'UNRESOLVED_IMPORT', + expectedWarnings: ['UNRESOLVED_IMPORT'], options: { external: id => { if (id === 'unresolved') return null; diff --git a/test/form/samples/import-assertions/keeps-static-assertions/_config.js b/test/form/samples/import-assertions/keeps-static-assertions/_config.js index 8780ad60a25..5dfbc1b2c0e 100644 --- a/test/form/samples/import-assertions/keeps-static-assertions/_config.js +++ b/test/form/samples/import-assertions/keeps-static-assertions/_config.js @@ -1,6 +1,6 @@ module.exports = defineTest({ description: 'keeps any import assertions on input', - expectedWarnings: 'UNRESOLVED_IMPORT', + expectedWarnings: ['UNRESOLVED_IMPORT'], options: { external: id => { if (id === 'unresolved') return null; diff --git a/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js b/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js index e16ab4730a8..5330ee734d0 100644 --- a/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js +++ b/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js @@ -1,6 +1,6 @@ module.exports = defineTest({ description: 'keep import assertions for dynamic imports', - expectedWarnings: 'UNRESOLVED_IMPORT', + expectedWarnings: ['UNRESOLVED_IMPORT'], options: { external: id => { if (id === 'unresolved') return null; diff --git a/test/form/samples/import-assertions/removes-static-assertions/_config.js b/test/form/samples/import-assertions/removes-static-assertions/_config.js index e48102f7749..8f8d7c07fd6 100644 --- a/test/form/samples/import-assertions/removes-static-assertions/_config.js +++ b/test/form/samples/import-assertions/removes-static-assertions/_config.js @@ -1,6 +1,6 @@ module.exports = defineTest({ description: 'keeps any import assertions on input', - expectedWarnings: 'UNRESOLVED_IMPORT', + expectedWarnings: ['UNRESOLVED_IMPORT'], options: { external: id => { if (id === 'unresolved') return null; diff --git a/test/function/index.js b/test/function/index.js index 56c8e81269d..80995398251 100644 --- a/test/function/index.js +++ b/test/function/index.js @@ -3,6 +3,7 @@ const path = require('node:path'); /** * @type {import('../../src/rollup/types')} Rollup */ +// @ts-expect-error not included in types const rollup = require('../../dist/rollup'); const { compareError, compareWarnings, runTestSuiteWithSamples } = require('../utils.js'); @@ -58,9 +59,11 @@ runTestSuiteWithSamples( (directory, config) => { (config.skip ? it.skip : config.solo ? it.only : it)( path.basename(directory) + ': ' + config.description, - () => { + async () => { if (config.show) console.group(path.basename(directory)); - if (config.before) config.before(); + if (config.before) { + await config.before(); + } process.chdir(directory); const warnings = []; @@ -173,7 +176,9 @@ runTestSuiteWithSamples( } if (config.show) console.groupEnd(); if (unintendedError) throw unintendedError; - if (config.after) config.after(); + if (config.after) { + return config.after(); + } }); }); }) @@ -183,7 +188,9 @@ runTestSuiteWithSamples( } else { throw error; } - if (config.after) config.after(); + if (config.after) { + return config.after(); + } }); } ); diff --git a/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js b/test/function/samples/transform-without-sourcemap-render-chunk/_config.js similarity index 95% rename from test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js rename to test/function/samples/transform-without-sourcemap-render-chunk/_config.js index 11336d4d5cf..46076d52430 100644 --- a/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js +++ b/test/function/samples/transform-without-sourcemap-render-chunk/_config.js @@ -17,7 +17,8 @@ module.exports = defineTest({ return { code, map: null }; } } - ] + ], + output: { sourcemap: true } }, warnings: [ { diff --git a/test/function/samples/transform-without-sourcemap-render-chunk/main.js b/test/function/samples/transform-without-sourcemap-render-chunk/main.js new file mode 100644 index 00000000000..69305ae375a --- /dev/null +++ b/test/function/samples/transform-without-sourcemap-render-chunk/main.js @@ -0,0 +1 @@ +assert.strictEqual(42, 42); diff --git a/test/sourcemaps/index.js b/test/sourcemaps/index.js index ece3af688f2..8e49fea4797 100644 --- a/test/sourcemaps/index.js +++ b/test/sourcemaps/index.js @@ -2,7 +2,9 @@ const path = require('node:path'); /** * @type {import('../../src/rollup/types')} Rollup */ +// @ts-expect-error not included in types const rollup = require('../../dist/rollup'); +// @ts-expect-error not included in types const { compareWarnings, runTestSuiteWithSamples } = require('../utils.js'); const FORMATS = ['amd', 'cjs', 'system', 'es', 'iife', 'umd']; @@ -10,11 +12,14 @@ const FORMATS = ['amd', 'cjs', 'system', 'es', 'iife', 'umd']; runTestSuiteWithSamples( 'sourcemaps', path.resolve(__dirname, 'samples'), - (directory, configuration) => { - (configuration.skip ? describe.skip : configuration.solo ? describe.only : describe)( - path.basename(directory) + ': ' + configuration.description, + /** + * @param {import('../types').TestConfigSourcemap} config + */ + (directory, config) => { + (config.skip ? describe.skip : config.solo ? describe.only : describe)( + path.basename(directory) + ': ' + config.description, () => { - for (const format of configuration.formats || FORMATS) { + for (const format of config.formats || FORMATS) { it('generates ' + format, async () => { process.chdir(directory); const warnings = []; @@ -22,25 +27,25 @@ runTestSuiteWithSamples( input: directory + '/main.js', onwarn: warning => warnings.push(warning), strictDeprecations: true, - ...configuration.options + ...config.options }; const outputOptions = { exports: 'auto', file: directory + '/_actual/bundle.' + format + '.js', format, sourcemap: true, - ...(configuration.options || {}).output + ...(config.options || {}).output }; let bundle = await rollup.rollup(inputOptions); - await generateAndTestBundle(bundle, outputOptions, configuration, format, warnings); + await generateAndTestBundle(bundle, outputOptions, config, format, warnings); // cache rebuild does not reemit warnings. - if (configuration.warnings) { + if (config.warnings) { return; } // test cache noop rebuild bundle = await rollup.rollup({ cache: bundle, ...inputOptions }); - await generateAndTestBundle(bundle, outputOptions, configuration, format, warnings); + await generateAndTestBundle(bundle, outputOptions, config, format, warnings); }); } } @@ -48,17 +53,14 @@ runTestSuiteWithSamples( } ); -async function generateAndTestBundle(bundle, outputOptions, configuration, format, warnings) { - await bundle.write(outputOptions); - if (configuration.warnings) { - compareWarnings(warnings, configuration.warnings); +async function generateAndTestBundle(bundle, outputOptions, config, format, warnings) { + if (config.warnings) { + compareWarnings(warnings, config.warnings); } else if (warnings.length > 0) { throw new Error(`Unexpected warnings`); } - if (configuration.test) { - const { - output: [{ code, map, fileName }] - } = await bundle.generate(outputOptions); - await configuration.test(code, map, { fileName, format }); - } + const { + output: [{ code, map, fileName }] + } = await bundle.generate(outputOptions); + await config.test(code, map, { fileName, format }); } diff --git a/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/main.js b/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/main.js deleted file mode 100644 index 5c72ff35124..00000000000 --- a/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log( 42 ); diff --git a/test/types.d.ts b/test/types.d.ts index 1a8a28cbdb6..d9d31b6f4dd 100644 --- a/test/types.d.ts +++ b/test/types.d.ts @@ -1,127 +1,233 @@ -/* eslint-disable @typescript-eslint/member-ordering */ import type { SourceMap } from 'magic-string'; import type { RollupBuild, RollupError, RollupOptions } from '../src/rollup/types'; export interface TestConfigBase { /** - * Only run this test. Should never be committed. + * Description of the test. Determines the name of the test in the test + * runner. */ - solo?: boolean; + description: string; + /** + * Only run this test if the major Node version is high enough. + */ + minNodeVersion?: number; + /** + * Only run this test on Windows. + */ + onlyWindows?: boolean; /** * Skip this test. */ skip?: boolean; /** - * Display in the test output. + * Do not run this test on Windows. */ - show?: boolean; + skipIfWindows?: boolean; /** - * Execute the bundled code. + * Only run this test. Should never be committed. */ - execute?: boolean; + solo?: boolean; +} +export interface TestConfigBrowser extends TestConfigBase { /** - * Description of the test. + * Expected error when running rollup.rollup() */ - description: string; + error?: RollupError; /** - * Rollup options + * Expected warning codes. Any of these warnings will not cause the test to + * fail. + */ + expectedWarnings?: string[]; + /** + * Expected error when running bundle.generate(). + */ + generateError?: RollupError; + /** + * Rollup options for bundling. */ options?: RollupOptions; +} + +export interface TestConfigChunkingForm extends TestConfigBase { /** - * Bundle formats to test. + * Called after the test is run. */ - formats?: string[]; + after?: () => void | Promise; /** - * The global context executed the bundled code. + * Called before the test is run. */ - context?: Record; + before?: () => void | Promise; /** - * The directory to run the test in. + * Expected warning codes. Any of these warnings will not cause the test to + * fail. + */ + expectedWarnings?: string[]; + /** + * The directory to bundle the code in. */ nestedDir?: string; + /** + * Rollup options for bundling. + */ + options?: RollupOptions; + /** + * Execute the AMD module. + */ + runAmd?: + | boolean + | { + exports?: (exportObject: any) => void | Promise; + }; +} +export interface TestConfigCli extends TestConfigBase { /** - * Called before the test is run. + * Assert the stderr stream, return true to abort the test. */ - before?: () => void | Promise; + abortOnStderr?: (data: string) => boolean | void | Promise; /** * Called after the test is run. */ - after?: () => void | Promise; - + after?: (error: Error | null, stdout: string, stderr: string) => void | Promise; /** - * Test the expected error. + * Called before the test is run. */ - error?: RollupError; - generateError?: RollupError; + before?: () => void | Promise; + command?: string; + cwd?: string; /** - * Test the expected warnings. + * Environment variables to set for the test. */ - warnings?: RollupError[] | ((warnings: RollupError[]) => boolean | void); + env?: Record; /** - * Expected warning codes + * Test the expected error. Assertions about the test output will only + * be performed afterward if you return "true" or do not supply this option. */ - expectedWarnings?: string | string[]; + error?: (error: RollupError) => boolean | void; /** - * Test the output of the build. + * Execute the bundled code. */ - test?: (code: string, map: SourceMap) => void | Promise; + execute?: boolean; /** - * Assetions for the exports of the bundle. + * Run assertions against the exports of the bundle after executing it. */ exports?: (exportObject: any) => void | Promise; - - skipIfWindows?: boolean; - onlyWindows?: boolean; - minNodeVersion?: string; + /** + * Run assertions against the generated code when bundling to stdout. + */ + result?: (code: string) => void; + retry?: number; + /** + * Display generated output in console. + */ + show?: boolean; + /** + * Assert the stderr of the build. Assertions about the test output will only + * be performed afterward if you return "true" or do not supply this option. + */ + stderr?: (stderr: string) => boolean | undefined; + /** + * Run assertions after the command has finished. + */ + test?: () => void; } -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface TestConfigForm extends TestConfigBase {} -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface TestConfigSourcemap extends TestConfigBase {} - export interface TestConfigFileHash extends TestConfigBase { - options1?: RollupOptions; - options2?: RollupOptions; + options1: RollupOptions; + options2: RollupOptions; } -export interface TestConfigCli extends TestConfigBase { - command?: string; - cwd?: string; - retry?: number; +export interface TestConfigForm extends TestConfigBase { /** - * Environment variables to set for the test. + * Called after the test is run. */ - env?: Record; + after?: () => void | Promise; /** - * Assert the stderr of the build. + * Called before the test is run. */ - stderr?: (stderr: string) => void | Promise; + before?: () => void | Promise; /** - * Assert the stderr stream, return true to abort the test. + * Expected warning codes. Any of these warnings will not cause the test to + * fail. */ - abortOnStderr?: (data: string) => boolean | void | Promise; - - result?: (code: string) => void; -} - -export interface TestConfigChunkingForm extends TestConfigBase { + expectedWarnings?: string[]; /** - * Execute the AMD module. + * Output formats to test. */ - runAmd?: - | boolean - | { - exports?: (exportObject: any) => void | Promise; - }; + formats?: string[]; + /** + * Rollup options for bundling. + */ + options?: RollupOptions; } export interface TestConfigFunction extends TestConfigBase { - runtimeError?(error: Error): void; - bundle?(bundle: RollupBuild): void; - code?(code: string): void; + /** + * Called after the test is run. + */ + after?: () => void | Promise; + /** + * Called before the test is run. + */ + before?: () => void | Promise; + /** + * Make assertions against the generated Rollup output object. + */ + bundle?: (bundle: RollupBuild) => void | Promise; + /** + * Make assertions against the generated code. + */ + code?: (code: string | Record) => void; + /** + * The global context executed the bundled code. + */ + context?: Record; + /** + * Expected error when running rollup.rollup() + */ + error?: RollupError; + /** + * Assetions for the exports of the bundle. + */ + exports?: (exportObject: any) => void | Promise; + /** + * Expected error when running bundle.generate(). + */ + generateError?: RollupError; + /** + * Make assertions against an expected runtime error. + */ + runtimeError?: (error: Error) => void; + /** + * Display generated output in console. + */ + show?: boolean; + /** + * Test the expected warnings. + */ + warnings?: RollupError[] | ((warnings: RollupError[]) => boolean | void); } -export type RunTestFunction = (directory: string, config: C) => void; +export interface TestConfigSourcemap extends TestConfigBase { + /** + * Output formats to test. + */ + formats?: string[]; + /** + * Rollup options for bundling. + */ + options?: RollupOptions; + /** + * Generate the bundle and run assertions. + */ + test: ( + code: string, + map: SourceMap, + options: { fileName: string; format: string } + ) => void | Promise; + /** + * List expected warnings. + */ + warnings?: RollupError[]; +}