diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index 8261008902e..f8850c3ca38 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -4,13 +4,13 @@ import relativeId from '../../src/utils/relativeId'; import { stderr } from '../logging'; export interface BatchWarnings { - add: (warning: string | RollupWarning) => void; + add: (warning: RollupWarning) => void; readonly count: number; flush: () => void; } export default function batchWarnings() { - let allWarnings = new Map(); + let deferredWarnings = new Map(); let count = 0; return { @@ -18,65 +18,44 @@ export default function batchWarnings() { return count; }, - add: (warning: string | RollupWarning) => { - if (typeof warning === 'string') { - warning = { code: 'UNKNOWN', message: warning }; - } + add: (warning: RollupWarning) => { + count += 1; - if (warning.code! in immediateHandlers) { + if (warning.code! in deferredHandlers) { + if (!deferredWarnings.has(warning.code!)) deferredWarnings.set(warning.code!, []); + deferredWarnings.get(warning.code!)!.push(warning); + } else if (warning.code! in immediateHandlers) { immediateHandlers[warning.code!](warning); - return; - } + } else { + title(warning.message); - if (!allWarnings.has(warning.code!)) allWarnings.set(warning.code!, []); - (allWarnings.get(warning.code!) as RollupWarning[]).push(warning); + if (warning.url) info(warning.url); - count += 1; - }, + const id = (warning.loc && warning.loc.file) || warning.id; + if (id) { + const loc = warning.loc + ? `${relativeId(id)}: (${warning.loc.line}:${warning.loc.column})` + : relativeId(id); - flush: () => { - if (count === 0) return; - - const codes = Array.from(allWarnings.keys()).sort((a, b) => { - if (deferredHandlers[a] && deferredHandlers[b]) { - return deferredHandlers[a].priority - deferredHandlers[b].priority; + stderr(tc.bold(relativeId(loc))); } - if (deferredHandlers[a]) return -1; - if (deferredHandlers[b]) return 1; - return ( - (allWarnings.get(b) as RollupWarning[]).length - - (allWarnings.get(a) as RollupWarning[]).length - ); - }); - - codes.forEach(code => { - const handler = deferredHandlers[code]; - const warnings = allWarnings.get(code); - - if (handler) { - handler.fn(warnings as RollupWarning[]); - } else { - (warnings as RollupWarning[]).forEach(warning => { - title(warning.message); - - if (warning.url) info(warning.url); + if (warning.frame) info(warning.frame); + } + }, - const id = (warning.loc && warning.loc.file) || warning.id; - if (id) { - const loc = warning.loc - ? `${relativeId(id)}: (${warning.loc.line}:${warning.loc.column})` - : relativeId(id); + flush: () => { + if (count === 0) return; - stderr(tc.bold(relativeId(loc))); - } + const codes = Array.from(deferredWarnings.keys()).sort( + (a, b) => deferredWarnings.get(b)!.length - deferredWarnings.get(a)!.length + ); - if (warning.frame) info(warning.frame); - }); - } - }); + for (const code of codes) { + deferredHandlers[code](deferredWarnings.get(code)!); + } - allWarnings = new Map(); + deferredWarnings = new Map(); count = 0; } }; @@ -113,171 +92,143 @@ const immediateHandlers: { } }; -// TODO select sensible priorities const deferredHandlers: { - [code: string]: { - fn: (warnings: RollupWarning[]) => void; - priority: number; - }; + [code: string]: (warnings: RollupWarning[]) => void; } = { - UNUSED_EXTERNAL_IMPORT: { - fn: warnings => { - title('Unused external imports'); - warnings.forEach(warning => { - stderr(`${warning.names} imported from external module '${warning.source}' but never used`); - }); - }, - priority: 1 + CIRCULAR_DEPENDENCY(warnings) { + title(`Circular dependenc${warnings.length > 1 ? 'ies' : 'y'}`); + const displayed = warnings.length > 5 ? warnings.slice(0, 3) : warnings; + for (const warning of displayed) { + stderr(warning.cycle!.join(' -> ')); + } + if (warnings.length > displayed.length) { + stderr(`...and ${warnings.length - displayed.length} more`); + } }, - UNRESOLVED_IMPORT: { - fn: warnings => { - title('Unresolved dependencies'); - info('https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'); - - const dependencies = new Map(); - warnings.forEach(warning => { - if (!dependencies.has(warning.source)) dependencies.set(warning.source, []); - dependencies.get(warning.source).push(warning.importer); - }); - - Array.from(dependencies.keys()).forEach(dependency => { - const importers = dependencies.get(dependency); - stderr(`${tc.bold(dependency)} (imported by ${importers.join(', ')})`); - }); - }, - priority: 1 + UNUSED_EXTERNAL_IMPORT(warnings) { + title('Unused external imports'); + for (const warning of warnings) { + stderr(`${warning.names} imported from external module '${warning.source}' but never used`); + } }, - MISSING_EXPORT: { - fn: warnings => { - title('Missing exports'); - info('https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module'); + UNRESOLVED_IMPORT(warnings) { + title('Unresolved dependencies'); + info('https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'); - warnings.forEach(warning => { - stderr(tc.bold(warning.importer!)); - stderr(`${warning.missing} is not exported by ${warning.exporter}`); - stderr(tc.gray(warning.frame!)); - }); - }, - priority: 1 + const dependencies = new Map(); + for (const warning of warnings) { + if (!dependencies.has(warning.source)) dependencies.set(warning.source, []); + dependencies.get(warning.source).push(warning.importer); + } + + for (const dependency of dependencies.keys()) { + const importers = dependencies.get(dependency); + stderr(`${tc.bold(dependency)} (imported by ${importers.join(', ')})`); + } }, - THIS_IS_UNDEFINED: { - fn: warnings => { - title('`this` has been rewritten to `undefined`'); - info('https://rollupjs.org/guide/en/#error-this-is-undefined'); - showTruncatedWarnings(warnings); - }, - priority: 1 + MISSING_EXPORT(warnings) { + title('Missing exports'); + info('https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module'); + + for (const warning of warnings) { + stderr(tc.bold(warning.importer!)); + stderr(`${warning.missing} is not exported by ${warning.exporter}`); + stderr(tc.gray(warning.frame!)); + } }, - EVAL: { - fn: warnings => { - title('Use of eval is strongly discouraged'); - info('https://rollupjs.org/guide/en/#avoiding-eval'); - showTruncatedWarnings(warnings); - }, - priority: 1 + THIS_IS_UNDEFINED(warnings) { + title('`this` has been rewritten to `undefined`'); + info('https://rollupjs.org/guide/en/#error-this-is-undefined'); + showTruncatedWarnings(warnings); }, - NON_EXISTENT_EXPORT: { - fn: warnings => { - title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`); - showTruncatedWarnings(warnings); - }, - priority: 1 + EVAL(warnings) { + title('Use of eval is strongly discouraged'); + info('https://rollupjs.org/guide/en/#avoiding-eval'); + showTruncatedWarnings(warnings); }, - NAMESPACE_CONFLICT: { - fn: warnings => { - title(`Conflicting re-exports`); - warnings.forEach(warning => { - stderr( - `${tc.bold(relativeId(warning.reexporter!))} re-exports '${ - warning.name - }' from both ${relativeId(warning.sources![0])} and ${relativeId( - warning.sources![1] - )} (will be ignored)` - ); - }); - }, - priority: 1 + NON_EXISTENT_EXPORT(warnings) { + title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`); + showTruncatedWarnings(warnings); }, - MISSING_GLOBAL_NAME: { - fn: warnings => { - title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`); + NAMESPACE_CONFLICT(warnings) { + title(`Conflicting re-exports`); + for (const warning of warnings) { stderr( - `Use output.globals to specify browser global variable names corresponding to external modules` + `${tc.bold(relativeId(warning.reexporter!))} re-exports '${ + warning.name + }' from both ${relativeId(warning.sources![0])} and ${relativeId( + warning.sources![1] + )} (will be ignored)` ); - warnings.forEach(warning => { - stderr(`${tc.bold(warning.source!)} (guessing '${warning.guess}')`); - }); - }, - priority: 1 + } }, - SOURCEMAP_BROKEN: { - fn: warnings => { - title(`Broken sourcemap`); - info('https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect'); - - const plugins = Array.from(new Set(warnings.map(w => w.plugin).filter(Boolean))); - const detail = - plugins.length === 0 - ? '' - : plugins.length > 1 - ? ` (such as ${plugins - .slice(0, -1) - .map(p => `'${p}'`) - .join(', ')} and '${plugins.slice(-1)}')` - : ` (such as '${plugins[0]}')`; - - stderr(`Plugins that transform code${detail} should generate accompanying sourcemaps`); - }, - priority: 1 + MISSING_GLOBAL_NAME(warnings) { + title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`); + stderr( + `Use output.globals to specify browser global variable names corresponding to external modules` + ); + for (const warning of warnings) { + stderr(`${tc.bold(warning.source!)} (guessing '${warning.guess}')`); + } + }, + + SOURCEMAP_BROKEN(warnings) { + title(`Broken sourcemap`); + info('https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect'); + + const plugins = Array.from(new Set(warnings.map(w => w.plugin).filter(Boolean))); + const detail = + plugins.length > 1 + ? ` (such as ${plugins + .slice(0, -1) + .map(p => `'${p}'`) + .join(', ')} and '${plugins.slice(-1)}')` + : ` (such as '${plugins[0]}')`; + + stderr(`Plugins that transform code${detail} should generate accompanying sourcemaps`); }, - PLUGIN_WARNING: { - fn: warnings => { - const nestedByPlugin = nest(warnings, 'plugin'); + PLUGIN_WARNING(warnings) { + const nestedByPlugin = nest(warnings, 'plugin'); - nestedByPlugin.forEach(({ key: plugin, items }) => { - const nestedByMessage = nest(items, 'message'); + for (const { key: plugin, items } of nestedByPlugin) { + const nestedByMessage = nest(items, 'message'); - let lastUrl: string; + let lastUrl = ''; - nestedByMessage.forEach(({ key: message, items }) => { - title(`Plugin ${plugin}: ${message}`); - items.forEach(warning => { - if (warning.url !== lastUrl) info((lastUrl = warning.url!)); + for (const { key: message, items } of nestedByMessage) { + title(`Plugin ${plugin}: ${message}`); + for (const warning of items) { + if (warning.url && warning.url !== lastUrl) info((lastUrl = warning.url)); - if (warning.id) { - let loc = relativeId(warning.id); - if (warning.loc) { - loc += `: (${warning.loc.line}:${warning.loc.column})`; - } - stderr(tc.bold(loc)); + if (warning.id) { + let loc = relativeId(warning.id); + if (warning.loc) { + loc += `: (${warning.loc.line}:${warning.loc.column})`; } - if (warning.frame) info(warning.frame); - }); - }); - }); - }, - priority: 1 + stderr(tc.bold(loc)); + } + if (warning.frame) info(warning.frame); + } + } + } }, - EMPTY_BUNDLE: { - fn: warnings => { - title( - `Generated${warnings.length === 1 ? ' an' : ''} empty ${ - warnings.length > 1 ? 'chunks' : 'chunk' - }` - ); - stderr(warnings.map(warning => warning.chunkName!).join(', ')); - }, - priority: 1 + EMPTY_BUNDLE(warnings) { + title( + `Generated${warnings.length === 1 ? ' an' : ''} empty ${ + warnings.length > 1 ? 'chunks' : 'chunk' + }` + ); + stderr(warnings.map(warning => warning.chunkName!).join(', ')); } }; @@ -293,7 +244,7 @@ function nest(array: T[], prop: string) { const nested: { items: T[]; key: string }[] = []; const lookup = new Map(); - array.forEach(item => { + for (const item of array) { const key = (item as any)[prop]; if (!lookup.has(key)) { lookup.set(key, { @@ -301,11 +252,11 @@ function nest(array: T[], prop: string) { key }); - nested.push(lookup.get(key) as { items: T[]; key: string }); + nested.push(lookup.get(key)!); } - (lookup.get(key) as { items: T[]; key: string }).items.push(item); - }); + lookup.get(key)!.items.push(item); + } return nested; } @@ -313,17 +264,17 @@ function nest(array: T[], prop: string) { function showTruncatedWarnings(warnings: RollupWarning[]) { const nestedByModule = nest(warnings, 'id'); - const sliced = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule; - sliced.forEach(({ key: id, items }) => { + const displayedByModule = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule; + for (const { key: id, items } of displayedByModule) { stderr(tc.bold(relativeId(id))); stderr(tc.gray(items[0].frame!)); if (items.length > 1) { stderr(`...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}`); } - }); + } - if (nestedByModule.length > sliced.length) { - stderr(`\n...and ${nestedByModule.length - sliced.length} other files`); + if (nestedByModule.length > displayedByModule.length) { + stderr(`\n...and ${nestedByModule.length - displayedByModule.length} other files`); } } diff --git a/cli/run/build.ts b/cli/run/build.ts index ec2e5abe104..e8454e20580 100644 --- a/cli/run/build.ts +++ b/cli/run/build.ts @@ -81,8 +81,8 @@ export default function build( } } }) - .catch((err: any) => { - if (warnings.count > 0) warnings.flush(); + .catch((err: Error) => { + warnings.flush(); handleError(err); }); } diff --git a/src/Graph.ts b/src/Graph.ts index 49c6913ddfb..68fbf33f3f4 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -395,6 +395,7 @@ export default class Graph { for (const cyclePath of cyclePaths) { this.warn({ code: 'CIRCULAR_DEPENDENCY', + cycle: cyclePath, importer: cyclePath[0], message: `Circular dependency: ${cyclePath.join(' -> ')}` }); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 6add08a8fce..6c8397dee79 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -11,6 +11,7 @@ export interface RollupError extends RollupLogProps { export interface RollupWarning extends RollupLogProps { chunkName?: string; + cycle?: string[]; exporter?: string; exportName?: string; guess?: string; @@ -500,10 +501,10 @@ export interface OutputOptions { } export type WarningHandlerWithDefault = ( - warning: string | RollupWarning, + warning: RollupWarning, defaultHandler: WarningHandler ) => void; -export type WarningHandler = (warning: string | RollupWarning) => void; +export type WarningHandler = (warning: RollupWarning) => void; export interface SerializedTimings { [label: string]: [number, number, number]; diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index c37b5f92aec..c20a8348fab 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -154,9 +154,10 @@ function getLinkMap(graph: Graph) { graph.warn({ code: 'SOURCEMAP_BROKEN', - message: `Sourcemap is likely to be incorrect: a plugin${ - map.plugin ? ` ('${map.plugin}')` : `` - } was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, + message: + `Sourcemap is likely to be incorrect: a plugin (${map.plugin}) was used to transform ` + + "files, but didn't generate a sourcemap for the transformation. Consult the plugin " + + 'documentation for help', plugin: map.plugin, url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect` }); diff --git a/test/cli/samples/custom-frame-log-stack/_config.js b/test/cli/samples/custom-frame-log-stack/_config.js deleted file mode 100644 index dc959d9ab79..00000000000 --- a/test/cli/samples/custom-frame-log-stack/_config.js +++ /dev/null @@ -1,12 +0,0 @@ -const assert = require('assert'); - -module.exports = { - description: 'errors with code frames should also log error\'s stack', - command: 'rollup -c', - error: () => true, - stderr: stderr => { - assert.ok(/custom code frame/.test(stderr)); - assert.ok(/ at /.test(stderr)); - assert.ok(/\.[a-z]+:\d+:\d+\)?\n/i.test(stderr)); - } -}; diff --git a/test/cli/samples/custom-frame-log-stack/main.js b/test/cli/samples/custom-frame-log-stack/main.js deleted file mode 100644 index 983961490bb..00000000000 --- a/test/cli/samples/custom-frame-log-stack/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log("everyday I'm throwing"); diff --git a/test/cli/samples/custom-frame-log-stack/rollup.config.js b/test/cli/samples/custom-frame-log-stack/rollup.config.js deleted file mode 100644 index dcf59c3105a..00000000000 --- a/test/cli/samples/custom-frame-log-stack/rollup.config.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - input: 'main.js', - output: { - format: 'cjs' - }, - plugins: [ - { - transform() { - const err = new Error('My error.'); - err.frame = 'custom code frame'; - this.error(err); - } - }, - ] -}; diff --git a/test/cli/samples/custom-frame-with-pos/_config.js b/test/cli/samples/custom-frame-with-pos/_config.js index cc92a934cee..04eb7c52a6a 100644 --- a/test/cli/samples/custom-frame-with-pos/_config.js +++ b/test/cli/samples/custom-frame-with-pos/_config.js @@ -1,10 +1,15 @@ -const assert = require('assert'); +const { assertStderrIncludes } = require('../../../utils.js'); module.exports = { description: 'custom (plugin generated) code frame taking priority over pos generated one', command: 'rollup -c', error: () => true, - stderr: stderr => { - assert.ok(/custom code frame/.test(stderr)); - } + stderr: stderr => + assertStderrIncludes( + stderr, + '[!] (plugin at position 1) Error: My error.\n' + + 'main.js (1:5)\n' + + 'custom code frame\n' + + 'Error: My error.' + ) }; diff --git a/test/cli/samples/custom-frame/_config.js b/test/cli/samples/custom-frame/_config.js index bd2318495c7..1cb907bba8d 100644 --- a/test/cli/samples/custom-frame/_config.js +++ b/test/cli/samples/custom-frame/_config.js @@ -1,10 +1,16 @@ -const assert = require('assert'); +const { assertStderrIncludes } = require('../../../utils.js'); module.exports = { - description: 'errors with custom (plugin generated) code frame', + description: 'errors with plugin generated code frames also contain stack', command: 'rollup -c', error: () => true, stderr: stderr => { - assert.ok(/custom code frame/.test(stderr)); + assertStderrIncludes( + stderr, + '[!] (plugin at position 1) Error: My error.\n' + + 'main.js\ncustom code frame\nError: My error.\n' + + ' at Object.transform' + ); + assertStderrIncludes(stderr, 'rollup.config.js:11:17'); } }; diff --git a/test/cli/samples/empty-chunk-multiple/_config.js b/test/cli/samples/empty-chunk-multiple/_config.js index f2544764593..13d34e24120 100644 --- a/test/cli/samples/empty-chunk-multiple/_config.js +++ b/test/cli/samples/empty-chunk-multiple/_config.js @@ -1,10 +1,8 @@ -const assert = require('assert'); +const { assertStderrIncludes } = require('../../../utils.js'); module.exports = { description: 'shows warning when multiple chunks empty', command: 'rollup -c', error: () => true, - stderr: stderr => { - assert.ok(stderr.includes('(!) Generated empty chunks\na, b')); - } + stderr: stderr => assertStderrIncludes(stderr, '(!) Generated empty chunks\na, b') }; diff --git a/test/cli/samples/empty-chunk/_config.js b/test/cli/samples/empty-chunk/_config.js index d6799dcc875..dca18ece281 100644 --- a/test/cli/samples/empty-chunk/_config.js +++ b/test/cli/samples/empty-chunk/_config.js @@ -1,10 +1,8 @@ -const assert = require('assert'); +const { assertStderrIncludes } = require('../../../utils.js'); module.exports = { description: 'shows warning when chunk empty', command: 'rollup -c', error: () => true, - stderr: stderr => { - assert.ok(stderr.includes('(!) Generated an empty chunk\nmain')); - } + stderr: stderr => assertStderrIncludes(stderr, '(!) Generated an empty chunk\nmain') }; diff --git a/test/cli/samples/warn-broken-sourcemap/_config.js b/test/cli/samples/warn-broken-sourcemap/_config.js new file mode 100644 index 00000000000..596a4d33ae5 --- /dev/null +++ b/test/cli/samples/warn-broken-sourcemap/_config.js @@ -0,0 +1,18 @@ +const fs = require('fs'); +const path = require('path'); +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'displays warnings for broken sourcemaps', + command: 'rollup -c', + stderr: stderr => { + fs.unlinkSync(path.resolve(__dirname, 'bundle')); + fs.unlinkSync(path.resolve(__dirname, 'bundle.map')); + assertStderrIncludes( + stderr, + '(!) Broken sourcemap\n' + + 'https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect\n' + + "Plugins that transform code (such as 'test-plugin1', 'test-plugin2' and 'test-plugin3') should generate accompanying sourcemaps" + ); + } +}; diff --git a/test/cli/samples/warn-broken-sourcemap/main.js b/test/cli/samples/warn-broken-sourcemap/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/cli/samples/warn-broken-sourcemap/main.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/cli/samples/warn-broken-sourcemap/rollup.config.js b/test/cli/samples/warn-broken-sourcemap/rollup.config.js new file mode 100644 index 00000000000..c490546377b --- /dev/null +++ b/test/cli/samples/warn-broken-sourcemap/rollup.config.js @@ -0,0 +1,28 @@ +module.exports = { + input: 'main.js', + plugins: [ + { + name: 'test-plugin1', + transform(code) { + return code + '/*1*/'; + } + }, + { + name: 'test-plugin2', + transform(code) { + return code + '/*2*/'; + } + }, + { + name: 'test-plugin3', + transform(code) { + return code + '/*3*/'; + } + } + ], + output: { + format: 'esm', + file: 'bundle', + sourcemap: true + } +}; diff --git a/test/cli/samples/warn-circular-multiple/_config.js b/test/cli/samples/warn-circular-multiple/_config.js new file mode 100644 index 00000000000..1716c598cdb --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/_config.js @@ -0,0 +1,16 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns for multiple circular dependencies', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) Circular dependencies\n' + + 'main.js -> dep1.js -> main.js\n' + + 'main.js -> dep2.js -> main.js\n' + + 'main.js -> dep3.js -> main.js\n' + + '...and 3 more\n' + + '' + ) +}; diff --git a/test/cli/samples/warn-circular-multiple/dep1.js b/test/cli/samples/warn-circular-multiple/dep1.js new file mode 100644 index 00000000000..531ac38c188 --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/dep1.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep1'); diff --git a/test/cli/samples/warn-circular-multiple/dep2.js b/test/cli/samples/warn-circular-multiple/dep2.js new file mode 100644 index 00000000000..e291e1688d6 --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/dep2.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep2'); diff --git a/test/cli/samples/warn-circular-multiple/dep3.js b/test/cli/samples/warn-circular-multiple/dep3.js new file mode 100644 index 00000000000..4158ce8817f --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/dep3.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep3'); diff --git a/test/cli/samples/warn-circular-multiple/dep4.js b/test/cli/samples/warn-circular-multiple/dep4.js new file mode 100644 index 00000000000..403fa46aa10 --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/dep4.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep5'); diff --git a/test/cli/samples/warn-circular-multiple/dep5.js b/test/cli/samples/warn-circular-multiple/dep5.js new file mode 100644 index 00000000000..403fa46aa10 --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/dep5.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep5'); diff --git a/test/cli/samples/warn-circular-multiple/dep6.js b/test/cli/samples/warn-circular-multiple/dep6.js new file mode 100644 index 00000000000..7bb212d5128 --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/dep6.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep6'); diff --git a/test/cli/samples/warn-circular-multiple/main.js b/test/cli/samples/warn-circular-multiple/main.js new file mode 100644 index 00000000000..5dfa42a26ca --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/main.js @@ -0,0 +1,7 @@ +import './dep1.js'; +import './dep2.js'; +import './dep3.js'; +import './dep4.js'; +import './dep5.js'; +import './dep6.js'; +console.log('main'); diff --git a/test/cli/samples/warn-circular-multiple/rollup.config.js b/test/cli/samples/warn-circular-multiple/rollup.config.js new file mode 100644 index 00000000000..3fcdc63ccf3 --- /dev/null +++ b/test/cli/samples/warn-circular-multiple/rollup.config.js @@ -0,0 +1,6 @@ +module.exports = { + input: 'main.js', + output: { + format: 'esm' + } +}; diff --git a/test/cli/samples/warn-circular/_config.js b/test/cli/samples/warn-circular/_config.js new file mode 100644 index 00000000000..12af2aad385 --- /dev/null +++ b/test/cli/samples/warn-circular/_config.js @@ -0,0 +1,8 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns for circular dependencies', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes(stderr, '(!) Circular dependency\n' + 'main.js -> dep.js -> main.js\n') +}; diff --git a/test/cli/samples/warn-circular/dep.js b/test/cli/samples/warn-circular/dep.js new file mode 100644 index 00000000000..6a114bf75d0 --- /dev/null +++ b/test/cli/samples/warn-circular/dep.js @@ -0,0 +1,2 @@ +import './main.js'; +console.log('dep'); diff --git a/test/cli/samples/warn-circular/main.js b/test/cli/samples/warn-circular/main.js new file mode 100644 index 00000000000..16652315de2 --- /dev/null +++ b/test/cli/samples/warn-circular/main.js @@ -0,0 +1,2 @@ +import './dep.js'; +console.log('main'); diff --git a/test/cli/samples/warn-circular/rollup.config.js b/test/cli/samples/warn-circular/rollup.config.js new file mode 100644 index 00000000000..3fcdc63ccf3 --- /dev/null +++ b/test/cli/samples/warn-circular/rollup.config.js @@ -0,0 +1,6 @@ +module.exports = { + input: 'main.js', + output: { + format: 'esm' + } +}; diff --git a/test/cli/samples/warn-eval-multiple/_config.js b/test/cli/samples/warn-eval-multiple/_config.js new file mode 100644 index 00000000000..70f2e45346b --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/_config.js @@ -0,0 +1,28 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns when eval is used multiple times', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) Use of eval is strongly discouraged\n' + + 'https://rollupjs.org/guide/en/#avoiding-eval\n' + + 'dep1.js\n' + + '1: eval(\'console.log("Hello");\');\n' + + ' ^\n' + + 'dep2.js\n' + + '1: eval(\'console.log("Hello");\');\n' + + ' ^\n' + + '2: eval(\'console.log("Hello again");\');\n' + + '...and 1 other occurrence\n' + + 'dep3.js\n' + + '1: eval(\'console.log("Hello");\');\n' + + ' ^\n' + + '2: eval(\'console.log("Hello again");\');\n' + + '3: eval(\'console.log("Hello again and again");\');\n' + + '...and 2 other occurrences\n' + + '\n' + + '...and 3 other files' + ) +}; diff --git a/test/cli/samples/warn-eval-multiple/dep1.js b/test/cli/samples/warn-eval-multiple/dep1.js new file mode 100644 index 00000000000..a47f66e24e2 --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/dep1.js @@ -0,0 +1 @@ +eval('console.log("Hello");'); diff --git a/test/cli/samples/warn-eval-multiple/dep2.js b/test/cli/samples/warn-eval-multiple/dep2.js new file mode 100644 index 00000000000..f727828534e --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/dep2.js @@ -0,0 +1,2 @@ +eval('console.log("Hello");'); +eval('console.log("Hello again");'); diff --git a/test/cli/samples/warn-eval-multiple/dep3.js b/test/cli/samples/warn-eval-multiple/dep3.js new file mode 100644 index 00000000000..9146f3244c8 --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/dep3.js @@ -0,0 +1,3 @@ +eval('console.log("Hello");'); +eval('console.log("Hello again");'); +eval('console.log("Hello again and again");'); diff --git a/test/cli/samples/warn-eval-multiple/dep4.js b/test/cli/samples/warn-eval-multiple/dep4.js new file mode 100644 index 00000000000..a47f66e24e2 --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/dep4.js @@ -0,0 +1 @@ +eval('console.log("Hello");'); diff --git a/test/cli/samples/warn-eval-multiple/dep5.js b/test/cli/samples/warn-eval-multiple/dep5.js new file mode 100644 index 00000000000..a47f66e24e2 --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/dep5.js @@ -0,0 +1 @@ +eval('console.log("Hello");'); diff --git a/test/cli/samples/warn-eval-multiple/main.js b/test/cli/samples/warn-eval-multiple/main.js new file mode 100644 index 00000000000..4ccabe761ef --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/main.js @@ -0,0 +1,7 @@ +import './dep1.js'; +import './dep2.js'; +import './dep3.js'; +import './dep4.js'; +import './dep5.js'; + +eval('foo'); diff --git a/test/cli/samples/warn-eval-multiple/rollup.config.js b/test/cli/samples/warn-eval-multiple/rollup.config.js new file mode 100644 index 00000000000..3fcdc63ccf3 --- /dev/null +++ b/test/cli/samples/warn-eval-multiple/rollup.config.js @@ -0,0 +1,6 @@ +module.exports = { + input: 'main.js', + output: { + format: 'esm' + } +}; diff --git a/test/cli/samples/warn-eval/_config.js b/test/cli/samples/warn-eval/_config.js new file mode 100644 index 00000000000..e98c7daaf7c --- /dev/null +++ b/test/cli/samples/warn-eval/_config.js @@ -0,0 +1,15 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns when eval is used', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) Use of eval is strongly discouraged\n' + + 'https://rollupjs.org/guide/en/#avoiding-eval\n' + + 'main.js\n' + + "1: eval('foo');\n" + + ' ^' + ) +}; diff --git a/test/cli/samples/warn-eval/main.js b/test/cli/samples/warn-eval/main.js new file mode 100644 index 00000000000..8c1b9dfdc37 --- /dev/null +++ b/test/cli/samples/warn-eval/main.js @@ -0,0 +1 @@ +eval('foo'); diff --git a/test/cli/samples/warn-eval/rollup.config.js b/test/cli/samples/warn-eval/rollup.config.js new file mode 100644 index 00000000000..3fcdc63ccf3 --- /dev/null +++ b/test/cli/samples/warn-eval/rollup.config.js @@ -0,0 +1,6 @@ +module.exports = { + input: 'main.js', + output: { + format: 'esm' + } +}; diff --git a/test/cli/samples/warn-import-export/_config.js b/test/cli/samples/warn-import-export/_config.js new file mode 100644 index 00000000000..ac65d03491f --- /dev/null +++ b/test/cli/samples/warn-import-export/_config.js @@ -0,0 +1,53 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns about import and export related issues', + command: 'rollup -c', + stderr: stderr => { + assertStderrIncludes( + stderr, + '(!) Mixing named and default exports\n' + + "Consumers of your bundle will have to use bundle['default'] to access the default export, which may not be what you want. Use `output.exports: 'named'` to disable this warning\n" + ); + assertStderrIncludes( + stderr, + '(!) Unused external imports\n' + + "default imported from external module 'external' but never used\n" + ); + assertStderrIncludes( + stderr, + '(!) Import of non-existent export\n' + + 'main.js\n' + + "1: import unused from 'external';\n" + + "2: import * as dep from './dep.js';\n" + + "3: import alsoUnused from './dep.js';\n" + + ' ^\n' + + "4: import 'unresolvedExternal';\n" + ); + assertStderrIncludes( + stderr, + '(!) Missing exports\n' + + 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module\n' + + 'main.js\n' + + 'missing is not exported by dep.js\n' + + "4: import 'unresolvedExternal';\n" + + '5: \n' + + '6: export const missing = dep.missing;\n' + + ' ^\n' + + '7: export default 42;\n' + ); + assertStderrIncludes( + stderr, + '(!) Conflicting re-exports\n' + + "main.js re-exports 'foo' from both dep.js and dep2.js (will be ignored)\n" + + "main.js re-exports 'bar' from both dep.js and dep2.js (will be ignored)\n" + ); + assertStderrIncludes( + stderr, + '(!) Unresolved dependencies\n' + + 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency\n' + + 'unresolvedExternal (imported by main.js, dep.js)\n' + + 'otherUnresolvedExternal (imported by dep.js)\n' + ); + } +}; diff --git a/test/cli/samples/warn-import-export/dep.js b/test/cli/samples/warn-import-export/dep.js new file mode 100644 index 00000000000..641277b5c92 --- /dev/null +++ b/test/cli/samples/warn-import-export/dep.js @@ -0,0 +1,6 @@ +import 'unresolvedExternal'; +import 'otherUnresolvedExternal'; + +export const foo = 1; +export const bar = 2; +export const baz = 3; diff --git a/test/cli/samples/warn-import-export/dep2.js b/test/cli/samples/warn-import-export/dep2.js new file mode 100644 index 00000000000..6f658e5bb4c --- /dev/null +++ b/test/cli/samples/warn-import-export/dep2.js @@ -0,0 +1,3 @@ +export const foo = 4; +export const bar = 5; +export const quux = 6; diff --git a/test/cli/samples/warn-import-export/main.js b/test/cli/samples/warn-import-export/main.js new file mode 100644 index 00000000000..c58373bb0c2 --- /dev/null +++ b/test/cli/samples/warn-import-export/main.js @@ -0,0 +1,10 @@ +import unused from 'external'; +import * as dep from './dep.js'; +import alsoUnused from './dep.js'; +import 'unresolvedExternal'; + +export const missing = dep.missing; +export default 42; + +export * from './dep.js'; +export * from './dep2.js'; diff --git a/test/cli/samples/warn-import-export/rollup.config.js b/test/cli/samples/warn-import-export/rollup.config.js new file mode 100644 index 00000000000..13535909996 --- /dev/null +++ b/test/cli/samples/warn-import-export/rollup.config.js @@ -0,0 +1,7 @@ +module.exports = { + input: 'main.js', + external: ['external'], + output: { + format: 'cjs' + } +}; diff --git a/test/cli/samples/warn-missing-global-multiple/_config.js b/test/cli/samples/warn-missing-global-multiple/_config.js new file mode 100644 index 00000000000..4d6e61c9997 --- /dev/null +++ b/test/cli/samples/warn-missing-global-multiple/_config.js @@ -0,0 +1,15 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns when there are multiple missing globals', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) Missing global variable names\n' + + 'Use output.globals to specify browser global variable names corresponding to external modules\n' + + "external1 (guessing 'foo1')\n" + + "external2 (guessing 'foo2')\n" + + "external3 (guessing 'foo3')" + ) +}; diff --git a/test/cli/samples/warn-missing-global-multiple/main.js b/test/cli/samples/warn-missing-global-multiple/main.js new file mode 100644 index 00000000000..ff620a05cd7 --- /dev/null +++ b/test/cli/samples/warn-missing-global-multiple/main.js @@ -0,0 +1,5 @@ +import foo1 from 'external1'; +import foo2 from 'external2'; +import foo3 from 'external3'; + +console.log(foo1, foo2, foo3); diff --git a/test/cli/samples/warn-missing-global-multiple/rollup.config.js b/test/cli/samples/warn-missing-global-multiple/rollup.config.js new file mode 100644 index 00000000000..671f387f3cb --- /dev/null +++ b/test/cli/samples/warn-missing-global-multiple/rollup.config.js @@ -0,0 +1,8 @@ +module.exports = { + input: 'main.js', + external: ['external1', 'external2', 'external3'], + output: { + format: 'iife', + name: 'bundle' + } +}; diff --git a/test/cli/samples/warn-missing-global/_config.js b/test/cli/samples/warn-missing-global/_config.js new file mode 100644 index 00000000000..74a84a6cde1 --- /dev/null +++ b/test/cli/samples/warn-missing-global/_config.js @@ -0,0 +1,13 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns when there is a missing global variable name', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) Missing global variable name\n' + + 'Use output.globals to specify browser global variable names corresponding to external modules\n' + + "external (guessing 'foo')" + ) +}; diff --git a/test/cli/samples/warn-missing-global/main.js b/test/cli/samples/warn-missing-global/main.js new file mode 100644 index 00000000000..96decbbc428 --- /dev/null +++ b/test/cli/samples/warn-missing-global/main.js @@ -0,0 +1,2 @@ +import foo from 'external'; +console.log(foo); diff --git a/test/cli/samples/warn-missing-global/rollup.config.js b/test/cli/samples/warn-missing-global/rollup.config.js new file mode 100644 index 00000000000..4241f975e8c --- /dev/null +++ b/test/cli/samples/warn-missing-global/rollup.config.js @@ -0,0 +1,8 @@ +module.exports = { + input: 'main.js', + external: ['external'], + output: { + format: 'iife', + name: 'bundle' + } +}; diff --git a/test/cli/samples/warn-multiple/_config.js b/test/cli/samples/warn-multiple/_config.js new file mode 100644 index 00000000000..b59306033c9 --- /dev/null +++ b/test/cli/samples/warn-multiple/_config.js @@ -0,0 +1,35 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'aggregates warnings of different types', + command: 'rollup -c', + stderr: stderr => { + assertStderrIncludes( + stderr, + '(!) Missing shims for Node.js built-ins\n' + + "Creating a browser bundle that depends on 'url', 'assert' and 'path'. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins\n" + ); + assertStderrIncludes( + stderr, + '(!) Import of non-existent exports\n' + + 'main.js\n' + + "4: import assert from 'assert';\n" + + "5: import path from 'path';\n" + + "6: import {doesNotExist, alsoNotFound} from './dep.js';\n" + + ' ^\n' + + '7: \n' + + '8: export {url, assert, path};\n' + + '...and 1 other occurrence\n' + ); + assertStderrIncludes( + stderr, + + "(!) Module level directives cause errors when bundled, 'use stuff' was ignored.\n" + + 'main.js: (1:0)\n' + + "1: 'use stuff';\n" + + ' ^\n' + + '2: \n' + + "3: import url from 'url';\n" + ); + } +}; diff --git a/test/cli/samples/warn-multiple/dep.js b/test/cli/samples/warn-multiple/dep.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/cli/samples/warn-multiple/main.js b/test/cli/samples/warn-multiple/main.js new file mode 100644 index 00000000000..809f20ffe84 --- /dev/null +++ b/test/cli/samples/warn-multiple/main.js @@ -0,0 +1,8 @@ +'use stuff'; + +import url from 'url'; +import assert from 'assert'; +import path from 'path'; +import {doesNotExist, alsoNotFound} from './dep.js'; + +export {url, assert, path}; diff --git a/test/cli/samples/warn-multiple/rollup.config.js b/test/cli/samples/warn-multiple/rollup.config.js new file mode 100644 index 00000000000..74772f14525 --- /dev/null +++ b/test/cli/samples/warn-multiple/rollup.config.js @@ -0,0 +1,8 @@ +module.exports = { + input: 'main.js', + external: ['url', 'assert', 'path'], + output: { + name: 'bundle', + format: 'amd' + } +}; diff --git a/test/cli/samples/warn-plugin/_config.js b/test/cli/samples/warn-plugin/_config.js new file mode 100644 index 00000000000..0815e2feca6 --- /dev/null +++ b/test/cli/samples/warn-plugin/_config.js @@ -0,0 +1,18 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'displays warnings from plugins', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) Plugin test-plugin: First\n' + + '(!) Plugin test-plugin: Second\n' + + 'https://information\n' + + '(!) Plugin second-plugin: Third\n' + + 'other.js\n' + + '(!) Plugin second-plugin: Fourth\n' + + 'other.js: (1:2)\n' + + 'custom frame' + ) +}; diff --git a/test/cli/samples/warn-plugin/main.js b/test/cli/samples/warn-plugin/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/cli/samples/warn-plugin/main.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/cli/samples/warn-plugin/rollup.config.js b/test/cli/samples/warn-plugin/rollup.config.js new file mode 100644 index 00000000000..bd985d99739 --- /dev/null +++ b/test/cli/samples/warn-plugin/rollup.config.js @@ -0,0 +1,32 @@ +const path = require('path'); + +module.exports = { + input: 'main.js', + plugins: [ + { + name: 'test-plugin', + buildStart() { + this.warn('First'); + this.warn({ message: 'Second', url: 'https://information' }); + this.warn({ message: 'Second', url: 'https://information' }); + } + } + ], + output: { + format: 'esm', + plugins: [ + { + name: 'second-plugin', + renderStart() { + this.warn({ message: 'Third', id: path.resolve(__dirname, 'other.js') }); + this.warn({ + message: 'Fourth', + id: path.resolve(__dirname, 'other.js'), + loc: { line: 1, column: 2 }, + frame: 'custom frame' + }); + } + } + ] + } +}; diff --git a/test/cli/samples/warn-this/_config.js b/test/cli/samples/warn-this/_config.js new file mode 100644 index 00000000000..fe2ff4656de --- /dev/null +++ b/test/cli/samples/warn-this/_config.js @@ -0,0 +1,15 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'warns "this" is used on the top level', + command: 'rollup -c', + stderr: stderr => + assertStderrIncludes( + stderr, + '(!) `this` has been rewritten to `undefined`\n' + + 'https://rollupjs.org/guide/en/#error-this-is-undefined\n' + + 'main.js\n' + + '1: console.log(this);\n' + + ' ^' + ) +}; diff --git a/test/cli/samples/warn-this/main.js b/test/cli/samples/warn-this/main.js new file mode 100644 index 00000000000..4593c7185d1 --- /dev/null +++ b/test/cli/samples/warn-this/main.js @@ -0,0 +1 @@ +console.log(this); diff --git a/test/cli/samples/warn-this/rollup.config.js b/test/cli/samples/warn-this/rollup.config.js new file mode 100644 index 00000000000..4241f975e8c --- /dev/null +++ b/test/cli/samples/warn-this/rollup.config.js @@ -0,0 +1,8 @@ +module.exports = { + input: 'main.js', + external: ['external'], + output: { + format: 'iife', + name: 'bundle' + } +}; diff --git a/test/function/samples/already-deshadowed-import/_config.js b/test/function/samples/already-deshadowed-import/_config.js index 072b6459647..b8ce432d1ac 100644 --- a/test/function/samples/already-deshadowed-import/_config.js +++ b/test/function/samples/already-deshadowed-import/_config.js @@ -4,6 +4,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['bob.js', 'alice.js', 'bob.js'], importer: 'bob.js', message: 'Circular dependency: bob.js -> alice.js -> bob.js' } diff --git a/test/function/samples/can-import-self-treeshake/_config.js b/test/function/samples/can-import-self-treeshake/_config.js index 98770762cfd..7873b58b34a 100644 --- a/test/function/samples/can-import-self-treeshake/_config.js +++ b/test/function/samples/can-import-self-treeshake/_config.js @@ -3,6 +3,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['lib.js', 'lib.js'], importer: 'lib.js', message: 'Circular dependency: lib.js -> lib.js' }, diff --git a/test/function/samples/can-import-self/_config.js b/test/function/samples/can-import-self/_config.js index 5e99b362146..f49dfc06ef3 100644 --- a/test/function/samples/can-import-self/_config.js +++ b/test/function/samples/can-import-self/_config.js @@ -8,6 +8,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['lib.js', 'lib.js'], importer: 'lib.js', message: 'Circular dependency: lib.js -> lib.js' } diff --git a/test/function/samples/compact/_config.js b/test/function/samples/compact/_config.js index 8a330e31a45..e41b7457fa6 100644 --- a/test/function/samples/compact/_config.js +++ b/test/function/samples/compact/_config.js @@ -10,6 +10,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['main.js', 'main.js'], importer: 'main.js', message: 'Circular dependency: main.js -> main.js' } diff --git a/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js b/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js index 00a6286e004..60e42dcfb98 100644 --- a/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js +++ b/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js @@ -3,6 +3,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['f.js', 'g.js', 'f.js'], importer: 'f.js', message: 'Circular dependency: f.js -> g.js -> f.js' } diff --git a/test/function/samples/cycles-defaults/_config.js b/test/function/samples/cycles-defaults/_config.js index 9ead90eb736..84969a977d2 100644 --- a/test/function/samples/cycles-defaults/_config.js +++ b/test/function/samples/cycles-defaults/_config.js @@ -3,6 +3,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['a.js', 'b.js', 'a.js'], importer: 'a.js', message: 'Circular dependency: a.js -> b.js -> a.js' } diff --git a/test/function/samples/cycles-export-star/_config.js b/test/function/samples/cycles-export-star/_config.js index c58ddefedd0..b1f63718246 100644 --- a/test/function/samples/cycles-export-star/_config.js +++ b/test/function/samples/cycles-export-star/_config.js @@ -11,6 +11,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['a.js', 'b.js', 'a.js'], importer: 'a.js', message: 'Circular dependency: a.js -> b.js -> a.js' } diff --git a/test/function/samples/cycles-immediate/_config.js b/test/function/samples/cycles-immediate/_config.js index a1d17e7c191..8c4b9235fd3 100644 --- a/test/function/samples/cycles-immediate/_config.js +++ b/test/function/samples/cycles-immediate/_config.js @@ -3,6 +3,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['evens.js', 'odds.js', 'evens.js'], importer: 'evens.js', message: 'Circular dependency: evens.js -> odds.js -> evens.js' } diff --git a/test/function/samples/cycles-pathological-2/_config.js b/test/function/samples/cycles-pathological-2/_config.js index e915af535e9..727ee735637 100644 --- a/test/function/samples/cycles-pathological-2/_config.js +++ b/test/function/samples/cycles-pathological-2/_config.js @@ -4,16 +4,19 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['main.js', 'b.js', 'main.js'], importer: 'main.js', message: 'Circular dependency: main.js -> b.js -> main.js' }, { code: 'CIRCULAR_DEPENDENCY', + cycle: ['b.js', 'd.js', 'c.js', 'b.js'], importer: 'b.js', message: 'Circular dependency: b.js -> d.js -> c.js -> b.js' }, { code: 'CIRCULAR_DEPENDENCY', + cycle: ['main.js', 'b.js', 'd.js', 'c.js', 'main.js'], importer: 'main.js', message: 'Circular dependency: main.js -> b.js -> d.js -> c.js -> main.js' } diff --git a/test/function/samples/cycles-stack-overflow/_config.js b/test/function/samples/cycles-stack-overflow/_config.js index a56497ef845..7c01540e491 100644 --- a/test/function/samples/cycles-stack-overflow/_config.js +++ b/test/function/samples/cycles-stack-overflow/_config.js @@ -3,11 +3,13 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', + cycle: ['c.js', 'd.js', 'b.js', 'c.js'], importer: 'c.js', message: 'Circular dependency: c.js -> d.js -> b.js -> c.js' }, { code: 'CIRCULAR_DEPENDENCY', + cycle: ['c.js', 'd.js', 'c.js'], importer: 'c.js', message: 'Circular dependency: c.js -> d.js -> c.js' } diff --git a/test/sourcemaps/samples/deprecated/transform-without-sourcemap/_config.js b/test/sourcemaps/samples/deprecated/transform-without-sourcemap/_config.js index 0e08b7d75fc..7c99723aa26 100644 --- a/test/sourcemaps/samples/deprecated/transform-without-sourcemap/_config.js +++ b/test/sourcemaps/samples/deprecated/transform-without-sourcemap/_config.js @@ -30,7 +30,7 @@ module.exports = { { code: `SOURCEMAP_BROKEN`, plugin: 'fake plugin 1', - message: `Sourcemap is likely to be incorrect: a plugin ('fake plugin 1') was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, + message: `Sourcemap is likely to be incorrect: a plugin (fake plugin 1) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect` } ] diff --git a/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js b/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js index 703d4c85cad..ca874293a6a 100644 --- a/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js +++ b/test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js @@ -23,7 +23,7 @@ module.exports = { { code: `SOURCEMAP_BROKEN`, plugin: 'fake plugin 1', - message: `Sourcemap is likely to be incorrect: a plugin ('fake plugin 1') was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, + message: `Sourcemap is likely to be incorrect: a plugin (fake plugin 1) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect` } ] diff --git a/test/test.js b/test/test.js index 366ad843275..215525dbb9e 100644 --- a/test/test.js +++ b/test/test.js @@ -3,11 +3,6 @@ require('console-group').install(); describe('rollup', function() { this.timeout(10000); - - // To quickly check the effects of potential performance improvements - before(() => console.time('Total test time')); - after(() => console.timeEnd('Total test time')); - require('./misc/index.js'); require('./function/index.js'); require('./form/index.js'); diff --git a/test/utils.js b/test/utils.js index b8159f292c2..57791247fdb 100644 --- a/test/utils.js +++ b/test/utils.js @@ -12,6 +12,7 @@ exports.loader = loader; exports.normaliseOutput = normaliseOutput; exports.runTestSuiteWithSamples = runTestSuiteWithSamples; exports.assertDirectoriesAreEqual = assertDirectoriesAreEqual; +exports.assertStderrIncludes = assertStderrIncludes; function normaliseError(error) { delete error.stack; @@ -224,3 +225,12 @@ function assertFilesAreEqual(actualFiles, expectedFiles, dirs = []) { ); }); } + +function assertStderrIncludes(stderr, expected) { + // eslint-disable-next-line no-control-regex + const output = stderr.replace(/\x1b\[[^m]*m/g, ''); + assert.ok( + output.includes(expected), + `Could not find ${JSON.stringify(expected)} in ${JSON.stringify(output)}` + ); +}