From 341d987b64855504c0cf8e3a2ecea95d0a252e38 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 12 Mar 2024 06:15:54 +0100 Subject: [PATCH] Add locations to logs, warnings and error messages (#5424) --- cli/run/batchWarnings.ts | 26 +- src/utils/logger.ts | 3 +- src/utils/logs.ts | 42 +- src/utils/options/options.ts | 19 +- test/cli/samples/filter-logs/_config.js | 10 +- .../_config.js | 2 +- test/cli/samples/log-side-effects/_config.js | 15 +- test/cli/samples/logs/_config.js | 19 +- test/cli/samples/validate/_config.js | 4 +- test/cli/samples/warn-multiple/_config.js | 8 +- test/cli/samples/warn-plugin-loc/_config.js | 15 +- test/cli/samples/warn-plugin/_config.js | 20 +- .../cli/samples/watch/bundle-error/_config.js | 2 +- test/cli/samples/watch/filter-logs/_config.js | 10 +- test/form/samples/log-side-effects/_config.js | 4 +- .../_config.js | 2 +- .../double-default-export/_config.js | 2 +- .../double-named-export/_config.js | 2 +- .../double-named-reexport/_config.js | 2 +- .../duplicate-function-export/_config.js | 2 +- .../duplicate-import-fails/_config.js | 2 +- .../_config.js | 2 +- .../duplicate-namespace-export/_config.js | 2 +- .../duplicate-parameter-name/_config.js | 2 +- .../duplicate-var-export/_config.js | 2 +- .../reassign-import-fails/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../redeclare-class-function/_config.js | 2 +- .../redeclare-const-function/_config.js | 2 +- .../_config.js | 2 +- .../redeclare-import-var/_config.js | 2 +- .../redeclare-let-function/_config.js | 2 +- .../redeclare-let-nested-var/_config.js | 2 +- .../redeclare-nested-var-let/_config.js | 2 +- .../redeclare-parameter-let/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../redeclare-var-class/_config.js | 2 +- .../_config.js | 2 +- .../cannot-call-external-namespace/_config.js | 4 +- .../cannot-call-internal-namespace/_config.js | 4 +- .../_config.js | 4 +- .../circular-missed-reexports/_config.js | 3 +- .../named-import/_config.js | 2 +- .../namespace-import/_config.js | 2 +- .../samples/default-not-reexported/_config.js | 2 +- .../emit-from-output-options/_config.js | 2 +- .../set-asset-source-transform/_config.js | 2 +- .../set-source-in-output-options/_config.js | 2 +- .../_config.js | 2 +- .../samples/error-const-reassign/_config.js | 2 +- .../samples/error-parse-json/_config.js | 2 +- .../error-parse-unknown-extension/_config.js | 2 +- .../export-not-at-top-level-fails/_config.js | 2 +- .../warn-assertion-conflicts/_config.js | 4 +- .../warn-unresolvable-assertions/_config.js | 14 +- .../import-not-at-top-level-fails/_config.js | 2 +- .../import-of-unexported-fails/_config.js | 2 +- .../samples/invalid-addon-hook/_config.js | 2 +- .../load-module-error/buildEnd/_config.js | 4 +- .../load-module-error/buildStart/_config.js | 2 +- .../generateBundle/_config.js | 4 +- .../load-module-error/renderChunk/_config.js | 4 +- .../load-module-error/renderStart/_config.js | 4 +- .../load-module-error/resolveId/_config.js | 4 +- .../load-module-error/transform/_config.js | 2 +- .../logging/handle-logs-in-plugins/_config.js | 29 +- .../logging/log-from-options/_config.js | 2 +- .../log-from-plugin-onlog-onwarn/_config.js | 46 +- .../logging/log-from-plugin-onlog/_config.js | 26 +- .../logging/log-from-plugin-onwarn/_config.js | 14 +- .../_config.js | 20 +- .../log-from-plugin-options-onlog/_config.js | 12 +- .../log-from-plugin-options-onwarn/_config.js | 12 +- .../log-from-plugin-options-simple/_config.js | 4 +- .../logging/log-from-plugin-simple/_config.js | 14 +- .../samples/logging/loglevel-debug/_config.js | 25 +- .../samples/logging/loglevel-info/_config.js | 19 +- .../logging/loglevel-silent/_config.js | 2 +- .../samples/logging/loglevel-warn/_config.js | 13 +- .../logging/no-log-with-position/_config.js | 22 +- .../samples/logging/plugin-order/_config.js | 20 +- .../logging/promote-log-to-error/_config.js | 4 +- .../logging/this-error-onlog/_config.js | 2 +- .../transform-log-with-position/_config.js | 18 +- .../samples/module-level-directive/_config.js | 2 +- .../namespace-missing-export/_config.js | 2 +- .../_config.js | 6 +- .../namespace-update-import-fails/_config.js | 2 +- .../non-function-hook-async/_config.js | 2 +- .../samples/non-function-hook-sync/_config.js | 2 +- .../plugin-error-loc-instead-pos/_config.js | 2 +- .../samples/plugin-error/buildEnd/_config.js | 2 +- .../plugin-error/buildStart/_config.js | 2 +- .../plugin-error/generateBundle/_config.js | 2 +- .../samples/plugin-error/load/_config.js | 2 +- .../plugin-error/renderChunk/_config.js | 2 +- .../plugin-error/renderStart/_config.js | 2 +- .../samples/plugin-error/resolveId/_config.js | 2 +- .../samples/plugin-error/transform/_config.js | 2 +- .../plugin-warn-loc-instead-pos/_config.js | 2 +- test/function/samples/plugin-warn/_config.js | 4 +- .../samples/reexport-missing-error/_config.js | 2 +- .../_config.js | 2 +- .../samples/validate-output/_config.js | 2 +- .../warn-misplaced-annotations/_config.js | 6 +- test/function/samples/warn-on-eval/_config.js | 2 +- .../samples/warn-on-top-level-this/_config.js | 2 +- .../warn-on-unused-missing-imports/_config.js | 2 +- .../_config.js | 3 +- .../_config.js | 2 +- .../samples/warnings-to-string/_config.js | 2 +- test/hooks/index.js | 13 +- test/misc/sanity-checks.js | 2 +- test/watch/index.js | 663 +++++++++--------- 120 files changed, 754 insertions(+), 635 deletions(-) diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index 19b5197bcc8..ea49611430a 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -195,22 +195,18 @@ const deferredHandlers: { PLUGIN_WARNING(warnings) { const nestedByPlugin = nest(warnings, 'plugin'); - for (const { key: plugin, items } of nestedByPlugin) { + for (const { items } of nestedByPlugin) { const nestedByMessage = nest(items, 'message'); let lastUrl = ''; for (const { key: message, items } of nestedByMessage) { - title(`Plugin ${plugin}: ${message}`); + title(message); for (const warning of items) { if (warning.url && warning.url !== lastUrl) info((lastUrl = warning.url)); - const id = warning.id || warning.loc?.file; - if (id) { - let loc = relativeId(id); - if (warning.loc) { - loc += `: (${warning.loc.line}:${warning.loc.column})`; - } + const loc = formatLocation(warning); + if (loc) { stderr(bold(loc)); } if (warning.frame) info(warning.frame); @@ -273,11 +269,9 @@ function defaultBody(log: RollupLog): void { info(getRollupUrl(log.url)); } - const id = log.loc?.file || log.id; - if (id) { - const loc = log.loc ? `${relativeId(id)} (${log.loc.line}:${log.loc.column})` : relativeId(id); - - stderr(bold(relativeId(loc))); + const loc = formatLocation(log); + if (loc) { + stderr(bold(loc)); } if (log.frame) info(log.frame); @@ -340,3 +334,9 @@ function generateLogFilter(command: Record) { } return getLogFilter(filters); } + +function formatLocation(log: RollupLog): string | null { + const id = log.loc?.file || log.id; + if (!id) return null; + return log.loc ? `${id}:${log.loc.line}:${log.loc.column}` : id; +} diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 06068133774..f03229a8d77 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -11,7 +11,7 @@ import { getSortedValidatedPlugins } from './PluginDriver'; import { EMPTY_SET } from './blank'; import { doNothing } from './doNothing'; import { LOGLEVEL_DEBUG, LOGLEVEL_INFO, LOGLEVEL_WARN, logLevelPriority } from './logging'; -import { error } from './logs'; +import { augmentLogMessage, error } from './logs'; import { normalizeLog } from './options/options'; export function getLogger( @@ -23,6 +23,7 @@ export function getLogger( plugins = getSortedValidatedPlugins('onLog', plugins); const minimalPriority = logLevelPriority[logLevel]; const logger = (level: LogLevel, log: RollupLog, skipped: ReadonlySet = EMPTY_SET) => { + augmentLogMessage(log); const logPriority = logLevelPriority[level]; if (logPriority < minimalPriority) { return; diff --git a/src/utils/logs.ts b/src/utils/logs.ts index 6570e7a4e76..ae635907df7 100644 --- a/src/utils/logs.ts +++ b/src/utils/logs.ts @@ -37,8 +37,12 @@ export function error(base: Error | RollupLog): never { } export function getRollupError(base: RollupLog): Error & RollupLog { + augmentLogMessage(base); const errorInstance = Object.assign(new Error(base.message), base); - Object.defineProperty(errorInstance, 'name', { value: 'RollupError', writable: true }); + Object.defineProperty(errorInstance, 'name', { + value: 'RollupError', + writable: true + }); return errorInstance; } @@ -67,6 +71,32 @@ export function augmentCodeLocation( } } +const symbolAugmented = Symbol('augmented'); + +interface AugmentedRollupLog extends RollupLog { + [symbolAugmented]?: boolean; +} + +export function augmentLogMessage(log: AugmentedRollupLog): void { + // Make sure to only augment the log message once + if (!(log.plugin || log.loc) || log[symbolAugmented]) { + return; + } + log[symbolAugmented] = true; + let prefix = ''; + + if (log.plugin) { + prefix += `[plugin ${log.plugin}] `; + } + const id = log.id || log.loc?.file; + if (id) { + const position = log.loc ? ` (${log.loc.line}:${log.loc.column})` : ''; + prefix += `${relativeId(id)}${position}: `; + } + + log.message = prefix + log.message; +} + // Error codes should be sorted alphabetically while errors should be sorted by // error code below const ADDON_ERROR = 'ADDON_ERROR', @@ -323,7 +353,10 @@ export function logConstVariableReassignError() { } export function logDuplicateArgumentNameError(name: string): RollupLog { - return { code: DUPLICATE_ARGUMENT_NAME, message: `Duplicate argument name "${name}"` }; + return { + code: DUPLICATE_ARGUMENT_NAME, + message: `Duplicate argument name "${name}"` + }; } export function logDuplicateExportError(name: string): RollupLog { @@ -838,7 +871,10 @@ export function logParseError(message: string, pos?: number): RollupLog { } export function logRedeclarationError(name: string): RollupLog { - return { code: REDECLARATION_ERROR, message: `Identifier "${name}" has already been declared` }; + return { + code: REDECLARATION_ERROR, + message: `Identifier "${name}" has already been declared` + }; } export function logModuleParseError(error: Error, moduleId: string): RollupLog { diff --git a/src/utils/options/options.ts b/src/utils/options/options.ts index deeae178fd4..3e2ee2884dd 100644 --- a/src/utils/options/options.ts +++ b/src/utils/options/options.ts @@ -19,7 +19,6 @@ import { EMPTY_ARRAY } from '../blank'; import { LOGLEVEL_DEBUG, LOGLEVEL_ERROR, LOGLEVEL_WARN, logLevelPriority } from '../logging'; import { error, logInvalidOption, logUnknownOption } from '../logs'; import { printQuotedStringList } from '../printStringList'; -import relativeId from '../relativeId'; export interface GenericConfigObject { [key: string]: unknown; @@ -60,7 +59,7 @@ const getDefaultOnLog = (printLog: LogHandler, onwarn?: WarningHandlerWithDefaul const addLogToString = (log: RollupLog): RollupLog => { Object.defineProperty(log, 'toString', { - value: () => getExtendedLogMessage(log), + value: () => log.message, writable: true }); return log; @@ -73,21 +72,7 @@ export const normalizeLog = (log: RollupLog | string | (() => RollupLog | string ? normalizeLog(log()) : log; -const getExtendedLogMessage = (log: RollupLog): string => { - let prefix = ''; - - if (log.plugin) { - prefix += `(${log.plugin} plugin) `; - } - if (log.loc) { - prefix += `${relativeId(log.loc.file!)} (${log.loc.line}:${log.loc.column}) `; - } - - return prefix + log.message; -}; - -const defaultPrintLog: LogHandler = (level, log) => { - const message = getExtendedLogMessage(log); +const defaultPrintLog: LogHandler = (level, { message }) => { switch (level) { case LOGLEVEL_WARN: { return console.warn(message); diff --git a/test/cli/samples/filter-logs/_config.js b/test/cli/samples/filter-logs/_config.js index d629f0fabc0..f1308767fdd 100644 --- a/test/cli/samples/filter-logs/_config.js +++ b/test/cli/samples/filter-logs/_config.js @@ -14,11 +14,11 @@ module.exports = defineTest({ stderr, ` main.js → stdout... -first -second -third -fourth -fifth +[plugin test] first +[plugin test] second +[plugin test] third +[plugin test] fourth +[plugin test] fifth ` ); } diff --git a/test/cli/samples/handles-uncaught-errors-under-watch/_config.js b/test/cli/samples/handles-uncaught-errors-under-watch/_config.js index 7b78cd56a39..53829d1c075 100644 --- a/test/cli/samples/handles-uncaught-errors-under-watch/_config.js +++ b/test/cli/samples/handles-uncaught-errors-under-watch/_config.js @@ -5,6 +5,6 @@ module.exports = defineTest({ command: 'rollup --config rollup.config.js -w', error: () => true, stderr(stderr) { - assertIncludes(stderr, 'Uncaught RollupError: LOL'); + assertIncludes(stderr, 'Uncaught RollupError: [plugin test] LOL'); } }); diff --git a/test/cli/samples/log-side-effects/_config.js b/test/cli/samples/log-side-effects/_config.js index 676e9d1647d..7673415220f 100644 --- a/test/cli/samples/log-side-effects/_config.js +++ b/test/cli/samples/log-side-effects/_config.js @@ -1,3 +1,4 @@ +const { sep } = require('node:path'); const { assertIncludes } = require('../../../utils.js'); module.exports = defineTest({ @@ -6,27 +7,27 @@ module.exports = defineTest({ env: { FORCE_COLOR: undefined, NO_COLOR: true }, stderr: stderr => assertIncludes( - stderr, - `First side effect in dep-mapped.js is at (2:26) + stderr.replaceAll(__dirname + sep, 'CWD/'), + `dep-mapped.js (1:0): First side effect in dep-mapped.js is at (2:26) 1: const removed = true; 2: const alsoRemoved = true; console.log('mapped effect'); ^ -dep-mapped.js (1:0) +CWD/dep-mapped.js:1:0 1: console.log('mapped effect'); ^ -First side effect in dep-long-line.js is at (1:126) +dep-long-line.js (1:126): First side effect in dep-long-line.js is at (1:126) 1: /* This side effect is deeply hidden inside a very long line, beyond the 120-character limit that we impose for truncation */ console.lo... ^ -dep-long-line.js (1:126) +CWD/dep-long-line.js:1:126 1: /* This side effect is deeply hidden inside a very long line, beyond the 120-character limit that we impose for truncation */ console.lo... ^ -First side effect in main.js is at (3:0) +main.js (3:0): First side effect in main.js is at (3:0) 1: import './dep-mapped'; 2: import './dep-long-line'; 3: console.log('main effect'); ^ 4: console.log('other effect'); -main.js (3:0) +CWD/main.js:3:0 1: import './dep-mapped'; 2: import './dep-long-line'; 3: console.log('main effect'); diff --git a/test/cli/samples/logs/_config.js b/test/cli/samples/logs/_config.js index 46d108bb545..5d445eac43d 100644 --- a/test/cli/samples/logs/_config.js +++ b/test/cli/samples/logs/_config.js @@ -1,4 +1,5 @@ const assert = require('node:assert'); +const { sep } = require('node:path'); const BOLD = '\u001B[1m'; const BLUE = '\u001B[34m'; @@ -14,23 +15,23 @@ module.exports = defineTest({ env: { FORCE_COLOR: '1', TERM: 'xterm' }, stderr(stderr) { assert.strictEqual( - stderr, + stderr.replaceAll(__dirname + sep, 'CWD/'), `${CYAN} ${BOLD}main.js${REGULAR} → ${BOLD}stdout${REGULAR}...${NOCOLOR} -${BOLD}${CYAN}simple-info${NOCOLOR}${REGULAR} -${BOLD}${CYAN}complex-info${NOCOLOR}${REGULAR} +${BOLD}${CYAN}[plugin test] simple-info${NOCOLOR}${REGULAR} +${BOLD}${CYAN}[plugin test] complex-info${NOCOLOR}${REGULAR} ${GRAY}https://rollupjs.org/https://my-url.net${NOCOLOR} -${BOLD}${BLUE}simple-debug${NOCOLOR}${REGULAR} -${BOLD}${BLUE}complex-debug${NOCOLOR}${REGULAR} +${BOLD}${BLUE}[plugin test] simple-debug${NOCOLOR}${REGULAR} +${BOLD}${BLUE}[plugin test] complex-debug${NOCOLOR}${REGULAR} ${GRAY}https://rollupjs.org/https://my-url.net${NOCOLOR} -${BOLD}${CYAN}transform-info${NOCOLOR}${REGULAR} +${BOLD}${CYAN}[plugin test] main.js (1:12): transform-info${NOCOLOR}${REGULAR} ${GRAY}https://rollupjs.org/https://my-url.net${NOCOLOR} -${BOLD}main.js (1:12)${REGULAR} +${BOLD}CWD/main.js:1:12${REGULAR} ${GRAY}1: assert.ok( true ); ^${NOCOLOR} -${BOLD}${BLUE}transform-debug${NOCOLOR}${REGULAR} +${BOLD}${BLUE}[plugin test] main.js (1:13): transform-debug${NOCOLOR}${REGULAR} ${GRAY}https://rollupjs.org/https://my-url.net${NOCOLOR} -${BOLD}main.js (1:13)${REGULAR} +${BOLD}CWD/main.js:1:13${REGULAR} ${GRAY}1: assert.ok( true ); ^${NOCOLOR} ` diff --git a/test/cli/samples/validate/_config.js b/test/cli/samples/validate/_config.js index 823456c5977..87a46f0b355 100644 --- a/test/cli/samples/validate/_config.js +++ b/test/cli/samples/validate/_config.js @@ -8,8 +8,8 @@ module.exports = defineTest({ stderr: stderr => assertIncludes( stderr, - `(!) Chunk "out.js" is not valid JavaScript: Unterminated block comment. -out.js (3:20) + `(!) out.js (3:20): Chunk "out.js" is not valid JavaScript: Unterminated block comment. +out.js:3:20 1: console.log(2 ); 2: 3: console.log("end"); /* diff --git a/test/cli/samples/warn-multiple/_config.js b/test/cli/samples/warn-multiple/_config.js index d069fc6035b..a8f69e70d7e 100644 --- a/test/cli/samples/warn-multiple/_config.js +++ b/test/cli/samples/warn-multiple/_config.js @@ -1,3 +1,4 @@ +const { sep } = require('node:path'); const { assertIncludes } = require('../../../utils.js'); module.exports = defineTest({ @@ -31,10 +32,9 @@ module.exports = defineTest({ '8: export {url, assert, path};' ); assertIncludes( - stderr, - - '(!) Module level directives cause errors when bundled, "use stuff" in "main.js" was ignored.\n' + - 'main.js (1:0)\n' + + stderr.replaceAll(__dirname + sep, 'CWD/'), + '(!) main.js (1:0): Module level directives cause errors when bundled, "use stuff" in "main.js" was ignored.\n' + + 'CWD/main.js:1:0\n' + "1: 'use stuff';\n" + ' ^\n' + '2: \n' + diff --git a/test/cli/samples/warn-plugin-loc/_config.js b/test/cli/samples/warn-plugin-loc/_config.js index 2e773991428..4b432061287 100644 --- a/test/cli/samples/warn-plugin-loc/_config.js +++ b/test/cli/samples/warn-plugin-loc/_config.js @@ -1,3 +1,4 @@ +const { sep } = require('node:path'); const { assertIncludes } = require('../../../utils.js'); module.exports = defineTest({ @@ -5,13 +6,13 @@ module.exports = defineTest({ command: 'rollup -c', stderr: stderr => { assertIncludes( - stderr, - '(!) Plugin test: Warning with file and id\n' + - 'file1: (1:2)\n' + - '(!) Plugin test: Warning with file\n' + - 'file2: (2:3)\n' + - '(!) Plugin test: Warning with id\n' + - 'file-id3: (3:4)\n' + stderr.replaceAll(__dirname + sep, 'CWD/'), + '(!) [plugin test] file1 (1:2): Warning with file and id\n' + + 'CWD/file1:1:2\n' + + '(!) [plugin test] file2 (2:3): Warning with file\n' + + 'CWD/file2:2:3\n' + + '(!) [plugin test] file-id3 (3:4): Warning with id\n' + + 'CWD/file-id3:3:4\n' ); } }); diff --git a/test/cli/samples/warn-plugin/_config.js b/test/cli/samples/warn-plugin/_config.js index 0695b6c77f4..2d581d3f863 100644 --- a/test/cli/samples/warn-plugin/_config.js +++ b/test/cli/samples/warn-plugin/_config.js @@ -1,3 +1,4 @@ +const { sep } = require('node:path'); const { assertIncludes } = require('../../../utils.js'); module.exports = defineTest({ @@ -5,16 +6,19 @@ module.exports = defineTest({ command: 'rollup -c', env: { FORCE_COLOR: undefined, NO_COLOR: true }, stderr: stderr => { - assertIncludes(stderr, 'Fifth\nother.js\n'); assertIncludes( - stderr, - '(!) Plugin test-plugin: First\n' + - '(!) Plugin test-plugin: Second\n' + + stderr.replaceAll(__dirname + sep, 'CWD/'), + '[plugin second-plugin] other.js: Fifth\n' + 'CWD/other.js\n' + ); + assertIncludes( + stderr.replaceAll(__dirname + sep, 'CWD/'), + '(!) [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' + + '(!) [plugin second-plugin] other.js: Third\n' + + 'CWD/other.js\n' + + '(!) [plugin second-plugin] other.js (1:2): Fourth\n' + + 'CWD/other.js:1:2\n' + 'custom frame' ); } diff --git a/test/cli/samples/watch/bundle-error/_config.js b/test/cli/samples/watch/bundle-error/_config.js index 588f9ed50bd..b7946e15e4d 100644 --- a/test/cli/samples/watch/bundle-error/_config.js +++ b/test/cli/samples/watch/bundle-error/_config.js @@ -16,7 +16,7 @@ module.exports = defineTest({ setTimeout(() => unlinkSync(mainFile), 300); }, abortOnStderr(data) { - if (data.includes('[!] RollupError: Expression expected')) { + if (data.includes('[!] RollupError: main.js (1:0): Expression expected')) { setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500); return false; } diff --git a/test/cli/samples/watch/filter-logs/_config.js b/test/cli/samples/watch/filter-logs/_config.js index 50d7ef8cb9c..9157d5e69ca 100644 --- a/test/cli/samples/watch/filter-logs/_config.js +++ b/test/cli/samples/watch/filter-logs/_config.js @@ -19,11 +19,11 @@ module.exports = defineTest({ stderr, ` bundles main.js → _actual.js... -first -second -third -fourth -fifth +[plugin test] first +[plugin test] second +[plugin test] third +[plugin test] fourth +[plugin test] fifth created _actual.js` ); } diff --git a/test/form/samples/log-side-effects/_config.js b/test/form/samples/log-side-effects/_config.js index ad3ee03138b..ed517a127ab 100644 --- a/test/form/samples/log-side-effects/_config.js +++ b/test/form/samples/log-side-effects/_config.js @@ -28,7 +28,7 @@ module.exports = defineTest({ { level: 'info', code: 'FIRST_SIDE_EFFECT', - message: `First side effect in dep-mapped.js is at (2:26) + message: `dep-mapped.js (1:0): First side effect in dep-mapped.js is at (2:26) 1: const removed = true; 2: const alsoRemoved = true; console.log('mapped effect'); ^`, @@ -46,7 +46,7 @@ module.exports = defineTest({ { level: 'info', code: 'FIRST_SIDE_EFFECT', - message: `First side effect in main.js is at (2:0) + message: `main.js (2:0): First side effect in main.js is at (2:0) 1: import './dep-mapped'; 2: console.log('main effect'); ^ diff --git a/test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/_config.js b/test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/_config.js index 880360056f7..8751b31c249 100644 --- a/test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/_config.js +++ b/test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/_config.js @@ -23,6 +23,6 @@ module.exports = defineTest({ `, watchFiles: [ID_ARRAY_JSON, ID_MAIN], message: - '"default" is not exported by "array.json", imported by "main.js". (Note that you need @rollup/plugin-json to import JSON files)' + 'main.js (1:7): "default" is not exported by "array.json", imported by "main.js". (Note that you need @rollup/plugin-json to import JSON files)' } }); diff --git a/test/function/samples/ast-validations/double-default-export/_config.js b/test/function/samples/ast-validations/double-default-export/_config.js index c653c16a53b..1c4175b7164 100644 --- a/test/function/samples/ast-validations/double-default-export/_config.js +++ b/test/function/samples/ast-validations/double-default-export/_config.js @@ -6,7 +6,7 @@ module.exports = defineTest({ description: 'throws on double default exports', error: { code: 'DUPLICATE_EXPORT', - message: 'Duplicate export "default"', + message: 'foo.js (2:0): Duplicate export "default"', id: ID_FOO, pos: 18, watchFiles: [ID_FOO, ID_MAIN], diff --git a/test/function/samples/ast-validations/double-named-export/_config.js b/test/function/samples/ast-validations/double-named-export/_config.js index dec32b5882a..af6811c6656 100644 --- a/test/function/samples/ast-validations/double-named-export/_config.js +++ b/test/function/samples/ast-validations/double-named-export/_config.js @@ -6,7 +6,7 @@ module.exports = defineTest({ description: 'throws on duplicate named exports', error: { code: 'DUPLICATE_EXPORT', - message: 'Duplicate export "foo"', + message: 'foo.js (3:9): Duplicate export "foo"', id: ID_FOO, pos: 38, watchFiles: [ID_FOO, ID_MAIN], diff --git a/test/function/samples/ast-validations/double-named-reexport/_config.js b/test/function/samples/ast-validations/double-named-reexport/_config.js index e7b3df1fe63..009e412c77d 100644 --- a/test/function/samples/ast-validations/double-named-reexport/_config.js +++ b/test/function/samples/ast-validations/double-named-reexport/_config.js @@ -6,7 +6,7 @@ module.exports = defineTest({ description: 'throws on duplicate named exports', error: { code: 'DUPLICATE_EXPORT', - message: 'Duplicate export "foo"', + message: 'foo.js (3:9): Duplicate export "foo"', id: ID_FOO, pos: 38, watchFiles: [ID_FOO, ID_MAIN], diff --git a/test/function/samples/ast-validations/duplicate-function-export/_config.js b/test/function/samples/ast-validations/duplicate-function-export/_config.js index 72b5900c5bc..5d255f63fa9 100644 --- a/test/function/samples/ast-validations/duplicate-function-export/_config.js +++ b/test/function/samples/ast-validations/duplicate-function-export/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'throws on duplicate namespace exports', error: { code: 'DUPLICATE_EXPORT', - message: 'Duplicate export "foo"', + message: 'main.js (3:16): Duplicate export "foo"', id: ID_MAIN, pos: 54, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/duplicate-import-fails/_config.js b/test/function/samples/ast-validations/duplicate-import-fails/_config.js index bb943151c0a..5d313cc4d58 100644 --- a/test/function/samples/ast-validations/duplicate-import-fails/_config.js +++ b/test/function/samples/ast-validations/duplicate-import-fails/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'disallows duplicate imports', error: { code: 'REDECLARATION_ERROR', - message: 'Identifier "a" has already been declared', + message: 'main.js (2:9): Identifier "a" has already been declared', id: ID_MAIN, pos: 36, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/duplicate-import-specifier-fails/_config.js b/test/function/samples/ast-validations/duplicate-import-specifier-fails/_config.js index 22488814330..641d84416e5 100644 --- a/test/function/samples/ast-validations/duplicate-import-specifier-fails/_config.js +++ b/test/function/samples/ast-validations/duplicate-import-specifier-fails/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'disallows duplicate import specifiers', error: { code: 'REDECLARATION_ERROR', - message: 'Identifier "a" has already been declared', + message: 'main.js (1:12): Identifier "a" has already been declared', id: ID_MAIN, pos: 12, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/duplicate-namespace-export/_config.js b/test/function/samples/ast-validations/duplicate-namespace-export/_config.js index 517e51220c4..7a418d42c92 100644 --- a/test/function/samples/ast-validations/duplicate-namespace-export/_config.js +++ b/test/function/samples/ast-validations/duplicate-namespace-export/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'throws on duplicate namespace exports', error: { code: 'DUPLICATE_EXPORT', - message: 'Duplicate export "foo"', + message: 'main.js (3:12): Duplicate export "foo"', id: ID_MAIN, pos: 50, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/duplicate-parameter-name/_config.js b/test/function/samples/ast-validations/duplicate-parameter-name/_config.js index f4b6be3849a..9a048b8fd59 100644 --- a/test/function/samples/ast-validations/duplicate-parameter-name/_config.js +++ b/test/function/samples/ast-validations/duplicate-parameter-name/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'throws on duplicate parameter names as it would when running in strict mode', error: { code: 'DUPLICATE_ARGUMENT_NAME', - message: 'Duplicate argument name "a"', + message: 'main.js (1:15): Duplicate argument name "a"', id: ID_MAIN, pos: 15, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/duplicate-var-export/_config.js b/test/function/samples/ast-validations/duplicate-var-export/_config.js index 590076146cd..4572eee6004 100644 --- a/test/function/samples/ast-validations/duplicate-var-export/_config.js +++ b/test/function/samples/ast-validations/duplicate-var-export/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'throws on duplicate exports declared with "var"', error: { code: 'DUPLICATE_EXPORT', - message: 'Duplicate export "x"', + message: 'main.js (2:11): Duplicate export "x"', id: ID_MAIN, pos: 29, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/reassign-import-fails/_config.js b/test/function/samples/ast-validations/reassign-import-fails/_config.js index 71ca9a3ee3f..086d01cb779 100644 --- a/test/function/samples/ast-validations/reassign-import-fails/_config.js +++ b/test/function/samples/ast-validations/reassign-import-fails/_config.js @@ -19,7 +19,7 @@ module.exports = defineTest({ 8: x = 10; ^`, watchFiles: [ID_FOO, ID_MAIN], - message: 'Illegal reassignment of import "x" in "main.js".' + message: 'main.js (8:0): Illegal reassignment of import "x" in "main.js".' } }); diff --git a/test/function/samples/ast-validations/reassign-import-not-at-top-level-fails/_config.js b/test/function/samples/ast-validations/reassign-import-not-at-top-level-fails/_config.js index d26f7c87fc5..f48f99eb8de 100644 --- a/test/function/samples/ast-validations/reassign-import-not-at-top-level-fails/_config.js +++ b/test/function/samples/ast-validations/reassign-import-not-at-top-level-fails/_config.js @@ -20,7 +20,7 @@ module.exports = defineTest({ ^ 8: }`, watchFiles: [ID_FOO, ID_MAIN], - message: 'Illegal reassignment of import "x" in "main.js".' + message: 'main.js (7:2): Illegal reassignment of import "x" in "main.js".' } }); diff --git a/test/function/samples/ast-validations/redeclare-block-function-function/_config.js b/test/function/samples/ast-validations/redeclare-block-function-function/_config.js index e09240c8029..a020d9d761a 100644 --- a/test/function/samples/ast-validations/redeclare-block-function-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-block-function-function/_config.js @@ -17,7 +17,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 3 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (3:10): Identifier "foo" has already been declared', pos: 31, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-catch-scope-local-variable-function/_config.js b/test/function/samples/ast-validations/redeclare-catch-scope-local-variable-function/_config.js index 2c45719318b..3fa1e8df324 100644 --- a/test/function/samples/ast-validations/redeclare-catch-scope-local-variable-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-catch-scope-local-variable-function/_config.js @@ -17,7 +17,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 4 }, - message: 'Identifier "error" has already been declared', + message: 'main.js (4:10): Identifier "error" has already been declared', pos: 62, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-catch-scope-parameter-function/_config.js b/test/function/samples/ast-validations/redeclare-catch-scope-parameter-function/_config.js index 194d48f2604..6416f2c7702 100644 --- a/test/function/samples/ast-validations/redeclare-catch-scope-parameter-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-catch-scope-parameter-function/_config.js @@ -17,7 +17,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 5 }, - message: 'Identifier "a" has already been declared', + message: 'main.js (5:10): Identifier "a" has already been declared', pos: 64, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-catch-scope-parameter-var-outside-conflict/_config.js b/test/function/samples/ast-validations/redeclare-catch-scope-parameter-var-outside-conflict/_config.js index e506796eb94..5869cac02bd 100644 --- a/test/function/samples/ast-validations/redeclare-catch-scope-parameter-var-outside-conflict/_config.js +++ b/test/function/samples/ast-validations/redeclare-catch-scope-parameter-var-outside-conflict/_config.js @@ -18,7 +18,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 5 }, - message: 'Identifier "error" has already been declared', + message: 'main.js (5:5): Identifier "error" has already been declared', pos: 68, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-catch-scope-pattern-parameter-var/_config.js b/test/function/samples/ast-validations/redeclare-catch-scope-pattern-parameter-var/_config.js index fdc573398ef..dbecc5f9d31 100644 --- a/test/function/samples/ast-validations/redeclare-catch-scope-pattern-parameter-var/_config.js +++ b/test/function/samples/ast-validations/redeclare-catch-scope-pattern-parameter-var/_config.js @@ -17,7 +17,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 4 }, - message: 'Identifier "message" has already been declared', + message: 'main.js (4:5): Identifier "message" has already been declared', pos: 63, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-class-function/_config.js b/test/function/samples/ast-validations/redeclare-class-function/_config.js index 7a145430091..ef910f3a3d2 100644 --- a/test/function/samples/ast-validations/redeclare-class-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-class-function/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (2:9): Identifier "foo" has already been declared', pos: 22, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-const-function/_config.js b/test/function/samples/ast-validations/redeclare-const-function/_config.js index 82596bb11bb..f070c473602 100644 --- a/test/function/samples/ast-validations/redeclare-const-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-const-function/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (2:9): Identifier "foo" has already been declared', pos: 24, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-default-import-function/_config.js b/test/function/samples/ast-validations/redeclare-default-import-function/_config.js index ca8ce033062..b4b17b3b6a6 100644 --- a/test/function/samples/ast-validations/redeclare-default-import-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-default-import-function/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'throws when redeclaring a default import with a function', error: { code: 'REDECLARATION_ERROR', - message: 'Identifier "foo" has already been declared', + message: 'main.js (4:9): Identifier "foo" has already been declared', id: ID_MAIN, pos: 56, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/redeclare-import-var/_config.js b/test/function/samples/ast-validations/redeclare-import-var/_config.js index d7875704187..587535a6578 100644 --- a/test/function/samples/ast-validations/redeclare-import-var/_config.js +++ b/test/function/samples/ast-validations/redeclare-import-var/_config.js @@ -5,7 +5,7 @@ module.exports = defineTest({ description: 'throws when redeclaring an import with a var', error: { code: 'REDECLARATION_ERROR', - message: 'Identifier "foo" has already been declared', + message: 'main.js (4:4): Identifier "foo" has already been declared', id: ID_MAIN, pos: 55, watchFiles: [ID_MAIN], diff --git a/test/function/samples/ast-validations/redeclare-let-function/_config.js b/test/function/samples/ast-validations/redeclare-let-function/_config.js index 89fcc1264a7..f73e86b394f 100644 --- a/test/function/samples/ast-validations/redeclare-let-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-let-function/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (2:9): Identifier "foo" has already been declared', pos: 18, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-let-nested-var/_config.js b/test/function/samples/ast-validations/redeclare-let-nested-var/_config.js index a1c3353d8bd..6ae94ac8356 100644 --- a/test/function/samples/ast-validations/redeclare-let-nested-var/_config.js +++ b/test/function/samples/ast-validations/redeclare-let-nested-var/_config.js @@ -18,7 +18,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 4 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (4:8): Identifier "foo" has already been declared', pos: 34, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-nested-var-let/_config.js b/test/function/samples/ast-validations/redeclare-nested-var-let/_config.js index e0832203674..afbdf8fd080 100644 --- a/test/function/samples/ast-validations/redeclare-nested-var-let/_config.js +++ b/test/function/samples/ast-validations/redeclare-nested-var-let/_config.js @@ -18,7 +18,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 5 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (5:6): Identifier "foo" has already been declared', pos: 39, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-parameter-let/_config.js b/test/function/samples/ast-validations/redeclare-parameter-let/_config.js index 14687f22f7a..8b523e282b6 100644 --- a/test/function/samples/ast-validations/redeclare-parameter-let/_config.js +++ b/test/function/samples/ast-validations/redeclare-parameter-let/_config.js @@ -16,7 +16,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "x" has already been declared', + message: 'main.js (2:5): Identifier "x" has already been declared', pos: 23, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-top-level-function-function/_config.js b/test/function/samples/ast-validations/redeclare-top-level-function-function/_config.js index e486d0f1b42..5c617c24d0b 100644 --- a/test/function/samples/ast-validations/redeclare-top-level-function-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-top-level-function-function/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (2:9): Identifier "foo" has already been declared', pos: 27, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-top-level-var-function/_config.js b/test/function/samples/ast-validations/redeclare-top-level-var-function/_config.js index 887a39e6cdd..46f344e65e7 100644 --- a/test/function/samples/ast-validations/redeclare-top-level-var-function/_config.js +++ b/test/function/samples/ast-validations/redeclare-top-level-var-function/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (2:9): Identifier "foo" has already been declared', pos: 18, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/redeclare-var-class/_config.js b/test/function/samples/ast-validations/redeclare-var-class/_config.js index dee387ed811..45c20f9f69b 100644 --- a/test/function/samples/ast-validations/redeclare-var-class/_config.js +++ b/test/function/samples/ast-validations/redeclare-var-class/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ file: ID_MAIN, line: 2 }, - message: 'Identifier "foo" has already been declared', + message: 'main.js (2:6): Identifier "foo" has already been declared', pos: 15, watchFiles: [ID_MAIN] } diff --git a/test/function/samples/ast-validations/update-expression-of-import-fails/_config.js b/test/function/samples/ast-validations/update-expression-of-import-fails/_config.js index c4a525ab4b6..0be391dd4fc 100644 --- a/test/function/samples/ast-validations/update-expression-of-import-fails/_config.js +++ b/test/function/samples/ast-validations/update-expression-of-import-fails/_config.js @@ -19,7 +19,7 @@ module.exports = defineTest({ 3: a++; ^`, watchFiles: [ID_FOO, ID_MAIN], - message: 'Illegal reassignment of import "a" in "main.js".' + message: 'main.js (3:0): Illegal reassignment of import "a" in "main.js".' } }); diff --git a/test/function/samples/cannot-call-external-namespace/_config.js b/test/function/samples/cannot-call-external-namespace/_config.js index 72faabd454f..8b8fbed6732 100644 --- a/test/function/samples/cannot-call-external-namespace/_config.js +++ b/test/function/samples/cannot-call-external-namespace/_config.js @@ -7,8 +7,8 @@ module.exports = defineTest({ }, warnings(warnings) { assert.deepStrictEqual(warnings.map(String), [ - 'main.js (4:1) Cannot call a namespace ("foo").', - 'main.js (8:1) Cannot call a namespace ("foo").' + 'main.js (4:1): Cannot call a namespace ("foo").', + 'main.js (8:1): Cannot call a namespace ("foo").' ]); } }); diff --git a/test/function/samples/cannot-call-internal-namespace/_config.js b/test/function/samples/cannot-call-internal-namespace/_config.js index 15b28a84778..30a32c1c895 100644 --- a/test/function/samples/cannot-call-internal-namespace/_config.js +++ b/test/function/samples/cannot-call-internal-namespace/_config.js @@ -4,8 +4,8 @@ module.exports = defineTest({ description: 'warns if code calls an internal namespace', warnings(warnings) { assert.deepStrictEqual(warnings.map(String), [ - 'main.js (4:1) Cannot call a namespace ("foo").', - 'main.js (8:1) Cannot call a namespace ("foo").' + 'main.js (4:1): Cannot call a namespace ("foo").', + 'main.js (8:1): Cannot call a namespace ("foo").' ]); } }); diff --git a/test/function/samples/cannot-resolve-sourcemap-warning/_config.js b/test/function/samples/cannot-resolve-sourcemap-warning/_config.js index cfec197b8d4..0306bd7771c 100644 --- a/test/function/samples/cannot-resolve-sourcemap-warning/_config.js +++ b/test/function/samples/cannot-resolve-sourcemap-warning/_config.js @@ -26,7 +26,7 @@ module.exports = defineTest({ line: 1 }, message: - "Error when using sourcemap for reporting an error: Can't resolve original location of error.", + "main.js (1:15): Error when using sourcemap for reporting an error: Can't resolve original location of error.", pos: 15 }, { @@ -42,7 +42,7 @@ module.exports = defineTest({ line: 1 }, message: - "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", + "main.js (1:15): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", pos: 15, url: 'https://rollupjs.org/troubleshooting/#error-this-is-undefined' } diff --git a/test/function/samples/circular-missed-reexports/_config.js b/test/function/samples/circular-missed-reexports/_config.js index 95be334af7f..7213d590d97 100644 --- a/test/function/samples/circular-missed-reexports/_config.js +++ b/test/function/samples/circular-missed-reexports/_config.js @@ -25,7 +25,8 @@ module.exports = defineTest({ binding: 'doesNotExist', code: 'MISSING_EXPORT', id: ID_MAIN, - message: '"doesNotExist" is not exported by "dep1.js", imported by "main.js".', + message: + 'main.js (1:17): "doesNotExist" is not exported by "dep1.js", imported by "main.js".', exporter: ID_DEP1, pos: 17, loc: { diff --git a/test/function/samples/conflicting-reexports/named-import/_config.js b/test/function/samples/conflicting-reexports/named-import/_config.js index 976a35db78f..ed209d3b67d 100644 --- a/test/function/samples/conflicting-reexports/named-import/_config.js +++ b/test/function/samples/conflicting-reexports/named-import/_config.js @@ -25,6 +25,6 @@ module.exports = defineTest({ 2: 3: assert.strictEqual(foo, 1);`, watchFiles: [ID_FIRST, ID_MAIN, ID_REEXPORT, ID_SECOND], - message: '"foo" is not exported by "reexport.js", imported by "main.js".' + message: 'main.js (1:9): "foo" is not exported by "reexport.js", imported by "main.js".' } }); diff --git a/test/function/samples/conflicting-reexports/namespace-import/_config.js b/test/function/samples/conflicting-reexports/namespace-import/_config.js index 8823d067a77..b633dead37f 100644 --- a/test/function/samples/conflicting-reexports/namespace-import/_config.js +++ b/test/function/samples/conflicting-reexports/namespace-import/_config.js @@ -20,7 +20,7 @@ module.exports = defineTest({ code: 'MISSING_EXPORT', exporter: ID_REEXPORT, id: ID_MAIN, - message: '"foo" is not exported by "reexport.js", imported by "main.js".', + message: 'main.js (4:22): "foo" is not exported by "reexport.js", imported by "main.js".', url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module', pos: 125, loc: { diff --git a/test/function/samples/default-not-reexported/_config.js b/test/function/samples/default-not-reexported/_config.js index adbfc65eaa9..c1807d5c2a7 100644 --- a/test/function/samples/default-not-reexported/_config.js +++ b/test/function/samples/default-not-reexported/_config.js @@ -9,7 +9,7 @@ module.exports = defineTest({ binding: 'default', code: 'MISSING_EXPORT', exporter: ID_FOO, - message: '"default" is not exported by "foo.js", imported by "main.js".', + message: 'main.js (1:7): "default" is not exported by "foo.js", imported by "main.js".', id: ID_MAIN, pos: 7, watchFiles: [ID_BAR, ID_FOO, ID_MAIN], diff --git a/test/function/samples/emit-file/emit-from-output-options/_config.js b/test/function/samples/emit-file/emit-from-output-options/_config.js index 67c990065c7..10dec91e0bf 100644 --- a/test/function/samples/emit-file/emit-from-output-options/_config.js +++ b/test/function/samples/emit-file/emit-from-output-options/_config.js @@ -17,7 +17,7 @@ module.exports = defineTest({ code: 'PLUGIN_ERROR', hook: 'outputOptions', message: - 'Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.', + '[plugin at position 1] Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.', plugin: 'at position 1', pluginCode: 'CANNOT_EMIT_FROM_OPTIONS_HOOK' } diff --git a/test/function/samples/emit-file/set-asset-source-transform/_config.js b/test/function/samples/emit-file/set-asset-source-transform/_config.js index 246c294eddc..730ec1f770a 100644 --- a/test/function/samples/emit-file/set-asset-source-transform/_config.js +++ b/test/function/samples/emit-file/set-asset-source-transform/_config.js @@ -19,7 +19,7 @@ module.exports = defineTest({ hook: 'transform', id: path.join(__dirname, 'main.js'), message: - 'setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.', + '[plugin test-plugin] main.js: setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.', plugin: 'test-plugin', pluginCode: 'INVALID_SETASSETSOURCE', watchFiles: [path.join(__dirname, 'main.js')] diff --git a/test/function/samples/emit-file/set-source-in-output-options/_config.js b/test/function/samples/emit-file/set-source-in-output-options/_config.js index 0db14083493..19361049396 100644 --- a/test/function/samples/emit-file/set-source-in-output-options/_config.js +++ b/test/function/samples/emit-file/set-source-in-output-options/_config.js @@ -19,7 +19,7 @@ module.exports = defineTest({ code: 'PLUGIN_ERROR', hook: 'outputOptions', message: - 'Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.', + '[plugin at position 1] Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.', plugin: 'at position 1', pluginCode: 'CANNOT_EMIT_FROM_OPTIONS_HOOK' } diff --git a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js index 3d24ffa9c63..9cd989d4475 100644 --- a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js +++ b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js @@ -39,6 +39,6 @@ module.exports = defineTest({ 3: Object.assign({}, a); `, watchFiles: [ID_EMPTY, ID_MAIN], - message: '"default" is not exported by "empty.js", imported by "main.js".' + message: 'main.js (1:7): "default" is not exported by "empty.js", imported by "main.js".' } }); diff --git a/test/function/samples/error-const-reassign/_config.js b/test/function/samples/error-const-reassign/_config.js index f6edd23a5b6..6763e27b00d 100644 --- a/test/function/samples/error-const-reassign/_config.js +++ b/test/function/samples/error-const-reassign/_config.js @@ -14,7 +14,7 @@ module.exports = defineTest({ file: MAIN_ID, line: 2 }, - message: 'Cannot reassign a variable declared with `const`', + message: 'main.js (2:0): Cannot reassign a variable declared with `const`', pos: 15, watchFiles: [MAIN_ID] } diff --git a/test/function/samples/error-parse-json/_config.js b/test/function/samples/error-parse-json/_config.js index 494ac4c261c..c9794c01619 100644 --- a/test/function/samples/error-parse-json/_config.js +++ b/test/function/samples/error-parse-json/_config.js @@ -27,6 +27,6 @@ module.exports = defineTest({ `, watchFiles: [ID_JSON, ID_MAIN], message: - "Expected ';', '}' or (Note that you need @rollup/plugin-json to import JSON files)" + "file.json (2:8): Expected ';', '}' or (Note that you need @rollup/plugin-json to import JSON files)" } }); diff --git a/test/function/samples/error-parse-unknown-extension/_config.js b/test/function/samples/error-parse-unknown-extension/_config.js index 45a72f9ffed..9570bd753c4 100644 --- a/test/function/samples/error-parse-unknown-extension/_config.js +++ b/test/function/samples/error-parse-unknown-extension/_config.js @@ -27,6 +27,6 @@ module.exports = defineTest({ `, watchFiles: [ID_CSS, ID_MAIN], message: - 'Expression expected (Note that you need plugins to import files that are not JavaScript)' + 'file.css (1:0): Expression expected (Note that you need plugins to import files that are not JavaScript)' } }); diff --git a/test/function/samples/export-not-at-top-level-fails/_config.js b/test/function/samples/export-not-at-top-level-fails/_config.js index 0940179df16..5b347adf098 100644 --- a/test/function/samples/export-not-at-top-level-fails/_config.js +++ b/test/function/samples/export-not-at-top-level-fails/_config.js @@ -24,6 +24,6 @@ module.exports = defineTest({ 3: } `, watchFiles: [ID_MAIN], - message: "'import', and 'export' cannot be used outside of module code" + message: "main.js (2:2): 'import', and 'export' cannot be used outside of module code" } }); diff --git a/test/function/samples/import-assertions/warn-assertion-conflicts/_config.js b/test/function/samples/import-assertions/warn-assertion-conflicts/_config.js index 2877a666554..aae733ed2bb 100644 --- a/test/function/samples/import-assertions/warn-assertion-conflicts/_config.js +++ b/test/function/samples/import-assertions/warn-assertion-conflicts/_config.js @@ -23,7 +23,7 @@ module.exports = defineTest({ line: 3 }, message: - 'Module "main.js" tried to import "external" with "type": "bar" attributes, but it was already imported elsewhere with "type": "foo" attributes. Please ensure that import attributes for the same module are always consistent.', + 'main.js (3:0): Module "main.js" tried to import "external" with "type": "bar" attributes, but it was already imported elsewhere with "type": "foo" attributes. Please ensure that import attributes for the same module are always consistent.', pos: 61 }, { @@ -42,7 +42,7 @@ module.exports = defineTest({ line: 4 }, message: - 'Module "main.js" tried to import "external" with no attributes, but it was already imported elsewhere with "type": "foo" attributes. Please ensure that import attributes for the same module are always consistent.', + 'main.js (4:0): Module "main.js" tried to import "external" with no attributes, but it was already imported elsewhere with "type": "foo" attributes. Please ensure that import attributes for the same module are always consistent.', pos: 101 }, { diff --git a/test/function/samples/import-assertions/warn-unresolvable-assertions/_config.js b/test/function/samples/import-assertions/warn-unresolvable-assertions/_config.js index a5c68b35589..a246159ce05 100644 --- a/test/function/samples/import-assertions/warn-unresolvable-assertions/_config.js +++ b/test/function/samples/import-assertions/warn-unresolvable-assertions/_config.js @@ -11,7 +11,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', + 'main.js (1:0): Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', id: ID_MAIN, pos: 0, loc: { @@ -28,7 +28,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', + 'main.js (2:0): Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', id: ID_MAIN, pos: 32, loc: { @@ -46,7 +46,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', + 'main.js (4:30): Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', id: ID_MAIN, pos: 133, loc: { @@ -65,7 +65,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', + 'main.js (5:30): Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', id: ID_MAIN, pos: 173, loc: { @@ -84,7 +84,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', + 'main.js (6:30): Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', id: ID_MAIN, pos: 218, loc: { @@ -103,7 +103,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', + 'main.js (7:30): Rollup could not statically analyze an import attribute of a dynamic import in "main.js". Import attributes need to have string keys and values. The attribute will be removed.', id: ID_MAIN, pos: 263, loc: { @@ -121,7 +121,7 @@ module.exports = defineTest({ { code: 'INVALID_IMPORT_ATTRIBUTE', message: - 'Rollup could not statically analyze the options argument of a dynamic import in "main.js". Dynamic import options need to be an object with a nested attributes object.', + 'main.js (3:0): Rollup could not statically analyze the options argument of a dynamic import in "main.js". Dynamic import options need to be an object with a nested attributes object.', id: ID_MAIN, pos: 61, loc: { diff --git a/test/function/samples/import-not-at-top-level-fails/_config.js b/test/function/samples/import-not-at-top-level-fails/_config.js index 3d270e44912..955f060572b 100644 --- a/test/function/samples/import-not-at-top-level-fails/_config.js +++ b/test/function/samples/import-not-at-top-level-fails/_config.js @@ -24,6 +24,6 @@ module.exports = defineTest({ 3: } `, watchFiles: [ID_MAIN], - message: "'import', and 'export' cannot be used outside of module code" + message: "main.js (2:2): 'import', and 'export' cannot be used outside of module code" } }); diff --git a/test/function/samples/import-of-unexported-fails/_config.js b/test/function/samples/import-of-unexported-fails/_config.js index a50bbaf0664..6ab48fa5072 100644 --- a/test/function/samples/import-of-unexported-fails/_config.js +++ b/test/function/samples/import-of-unexported-fails/_config.js @@ -23,6 +23,6 @@ module.exports = defineTest({ 3: a(); `, watchFiles: [ID_EMPTY, ID_MAIN], - message: '"default" is not exported by "empty.js", imported by "main.js".' + message: 'main.js (1:7): "default" is not exported by "empty.js", imported by "main.js".' } }); diff --git a/test/function/samples/invalid-addon-hook/_config.js b/test/function/samples/invalid-addon-hook/_config.js index af0868765a7..d237b2e56c6 100644 --- a/test/function/samples/invalid-addon-hook/_config.js +++ b/test/function/samples/invalid-addon-hook/_config.js @@ -6,6 +6,6 @@ module.exports = defineTest({ generateError: { code: 'ADDON_ERROR', message: - 'Could not retrieve "intro". Check configuration of plugin "at position 1".\n\tError Message: Error running plugin hook "intro" for plugin "at position 1", expected a string, a function hook or an object with a "handler" string or function.' + 'Could not retrieve "intro". Check configuration of plugin "at position 1".\n\tError Message: [plugin at position 1] Error running plugin hook "intro" for plugin "at position 1", expected a string, a function hook or an object with a "handler" string or function.' } }); diff --git a/test/function/samples/load-module-error/buildEnd/_config.js b/test/function/samples/load-module-error/buildEnd/_config.js index 327db966a4a..6f28260f7ff 100644 --- a/test/function/samples/load-module-error/buildEnd/_config.js +++ b/test/function/samples/load-module-error/buildEnd/_config.js @@ -1,5 +1,5 @@ module.exports = defineTest({ - description: 'buildStart hooks can use this.error', + description: 'buildEnd hooks can use this.error', options: { plugins: [ { @@ -13,7 +13,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'buildEnd' } }); diff --git a/test/function/samples/load-module-error/buildStart/_config.js b/test/function/samples/load-module-error/buildStart/_config.js index 6ea085f42fc..fcc14543b60 100644 --- a/test/function/samples/load-module-error/buildStart/_config.js +++ b/test/function/samples/load-module-error/buildStart/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'buildStart' } }); diff --git a/test/function/samples/load-module-error/generateBundle/_config.js b/test/function/samples/load-module-error/generateBundle/_config.js index 7e17c2b92aa..cb61e5997b5 100644 --- a/test/function/samples/load-module-error/generateBundle/_config.js +++ b/test/function/samples/load-module-error/generateBundle/_config.js @@ -1,5 +1,5 @@ module.exports = defineTest({ - description: 'buildStart hooks can use this.error', + description: 'generateBundle hooks can use this.error', options: { plugins: [ { @@ -13,7 +13,7 @@ module.exports = defineTest({ generateError: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'generateBundle' } }); diff --git a/test/function/samples/load-module-error/renderChunk/_config.js b/test/function/samples/load-module-error/renderChunk/_config.js index dcc254529b6..fd328c46a6d 100644 --- a/test/function/samples/load-module-error/renderChunk/_config.js +++ b/test/function/samples/load-module-error/renderChunk/_config.js @@ -1,5 +1,5 @@ module.exports = defineTest({ - description: 'buildStart hooks can use this.error', + description: 'renderChunk hooks can use this.error', options: { plugins: [ { @@ -13,7 +13,7 @@ module.exports = defineTest({ generateError: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'renderChunk' } }); diff --git a/test/function/samples/load-module-error/renderStart/_config.js b/test/function/samples/load-module-error/renderStart/_config.js index 4756298ddb4..cea313619ea 100644 --- a/test/function/samples/load-module-error/renderStart/_config.js +++ b/test/function/samples/load-module-error/renderStart/_config.js @@ -1,5 +1,5 @@ module.exports = defineTest({ - description: 'buildStart hooks can use this.error', + description: 'renderStart hooks can use this.error', options: { plugins: [ { @@ -13,7 +13,7 @@ module.exports = defineTest({ generateError: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'renderStart' } }); diff --git a/test/function/samples/load-module-error/resolveId/_config.js b/test/function/samples/load-module-error/resolveId/_config.js index 9b3390ca35c..b63fb4d5014 100644 --- a/test/function/samples/load-module-error/resolveId/_config.js +++ b/test/function/samples/load-module-error/resolveId/_config.js @@ -1,5 +1,5 @@ module.exports = defineTest({ - description: 'buildStart hooks can use this.error', + description: 'resolveId hooks can use this.error', options: { plugins: [ { @@ -13,7 +13,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'resolveId' } }); diff --git a/test/function/samples/load-module-error/transform/_config.js b/test/function/samples/load-module-error/transform/_config.js index 1c893155d14..f31ea7dc464 100644 --- a/test/function/samples/load-module-error/transform/_config.js +++ b/test/function/samples/load-module-error/transform/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] main.js (1:22): nope', hook: 'transform', id: path.join(__dirname, 'main.js'), watchFiles: [path.join(__dirname, 'main.js')], diff --git a/test/function/samples/logging/handle-logs-in-plugins/_config.js b/test/function/samples/logging/handle-logs-in-plugins/_config.js index 82d80e9c45c..7d8e6dd96b6 100644 --- a/test/function/samples/logging/handle-logs-in-plugins/_config.js +++ b/test/function/samples/logging/handle-logs-in-plugins/_config.js @@ -58,24 +58,16 @@ module.exports = defineTest({ ] }, after() { - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ [ 'first', 'info', - { - message: 'passed to both plugins', - code: 'PLUGIN_LOG', - plugin: 'first' - } + { message: '[plugin first] passed to both plugins', code: 'PLUGIN_LOG', plugin: 'first' } ], [ 'second', 'info', - { - message: 'passed to both plugins', - code: 'PLUGIN_LOG', - plugin: 'first' - } + { message: '[plugin first] passed to both plugins', code: 'PLUGIN_LOG', plugin: 'first' } ], [ 'first', @@ -83,7 +75,7 @@ module.exports = defineTest({ { code: 'THIS_IS_UNDEFINED', message: - "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", + "main.js (2:5): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", url: 'https://rollupjs.org/troubleshooting/#error-this-is-undefined', id: ID_MAIN, pos: 24, @@ -101,7 +93,7 @@ module.exports = defineTest({ { code: 'THIS_IS_UNDEFINED', message: - "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", + "main.js (2:5): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", url: 'https://rollupjs.org/troubleshooting/#error-this-is-undefined', id: ID_MAIN, pos: 24, @@ -156,7 +148,7 @@ module.exports = defineTest({ code: 'EVAL', id: ID_MAIN, message: - 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + 'main.js (2:0): Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', url: 'https://rollupjs.org/troubleshooting/#avoiding-eval', pos: 19, loc: { @@ -201,7 +193,7 @@ module.exports = defineTest({ level: 'warn', code: 'THIS_IS_UNDEFINED', message: - "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", + "main.js (2:5): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", url: 'https://rollupjs.org/troubleshooting/#error-this-is-undefined', id: ID_MAIN, pos: 24, @@ -215,6 +207,11 @@ module.exports = defineTest({ 2: eval(this); ^` }, - { level: 'info', message: 'passed to both plugins', code: 'PLUGIN_LOG', plugin: 'first' } + { + level: 'info', + message: '[plugin first] passed to both plugins', + code: 'PLUGIN_LOG', + plugin: 'first' + } ] }); diff --git a/test/function/samples/logging/log-from-options/_config.js b/test/function/samples/logging/log-from-options/_config.js index 6caf0f85ee5..7fe79f869c9 100644 --- a/test/function/samples/logging/log-from-options/_config.js +++ b/test/function/samples/logging/log-from-options/_config.js @@ -22,7 +22,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', hook: 'onLog', - message: 'error', + message: '[plugin test] error', plugin: 'test' } }); diff --git a/test/function/samples/logging/log-from-plugin-onlog-onwarn/_config.js b/test/function/samples/logging/log-from-plugin-onlog-onwarn/_config.js index 0a8f7c945fc..6a480cbaa55 100644 --- a/test/function/samples/logging/log-from-plugin-onlog-onwarn/_config.js +++ b/test/function/samples/logging/log-from-plugin-onlog-onwarn/_config.js @@ -11,12 +11,12 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ [ 'onLog', 'warn', { - message: 'warnLog', + message: '[plugin test] warnLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', meta: { test: 'foo' }, @@ -27,39 +27,65 @@ module.exports = defineTest({ [ 'onLog', 'warn', - { message: 'warnLog', code: 'PLUGIN_WARNING', pluginCode: 'PLUGIN_CODE', plugin: 'test' } + { + message: '[plugin test] warnLog', + code: 'PLUGIN_WARNING', + pluginCode: 'PLUGIN_CODE', + plugin: 'test' + } + ], + [ + 'onLog', + 'warn', + { + message: '[plugin test] warnLog', + code: 'PLUGIN_WARNING', + pluginCode: 'THE_CODE', + plugin: 'test' + } + ], + [ + 'onLog', + 'warn', + { message: '[plugin test] warnLog', code: 'PLUGIN_WARNING', plugin: 'test' } ], [ 'onLog', 'warn', - { message: 'warnLog', code: 'PLUGIN_WARNING', pluginCode: 'THE_CODE', plugin: 'test' } + { message: '[plugin test] warnString', code: 'PLUGIN_WARNING', plugin: 'test' } ], - ['onLog', 'warn', { message: 'warnLog', code: 'PLUGIN_WARNING', plugin: 'test' }], - ['onLog', 'warn', { message: 'warnString', code: 'PLUGIN_WARNING', plugin: 'test' }], [ 'onLog', 'info', { - message: 'infoLog', + message: '[plugin test] infoLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', code: 'PLUGIN_LOG', plugin: 'test' } ], - ['onLog', 'info', { message: 'infoString', code: 'PLUGIN_LOG', plugin: 'test' }], + [ + 'onLog', + 'info', + { message: '[plugin test] infoString', code: 'PLUGIN_LOG', plugin: 'test' } + ], [ 'onLog', 'debug', { - message: 'debugLog', + message: '[plugin test] debugLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', code: 'PLUGIN_LOG', plugin: 'test' } ], - ['onLog', 'debug', { message: 'debugString', code: 'PLUGIN_LOG', plugin: 'test' }] + [ + 'onLog', + 'debug', + { message: '[plugin test] debugString', code: 'PLUGIN_LOG', plugin: 'test' } + ] ]); }, options: { diff --git a/test/function/samples/logging/log-from-plugin-onlog/_config.js b/test/function/samples/logging/log-from-plugin-onlog/_config.js index 66d9a137501..a5f486fe9d7 100644 --- a/test/function/samples/logging/log-from-plugin-onlog/_config.js +++ b/test/function/samples/logging/log-from-plugin-onlog/_config.js @@ -11,43 +11,55 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ [ 'onLog', 'warn', { - message: 'warnLog', + message: '[plugin test] warnLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', code: 'PLUGIN_WARNING', plugin: 'test' } ], - ['onLog', 'warn', { message: 'warnString', code: 'PLUGIN_WARNING', plugin: 'test' }], + [ + 'onLog', + 'warn', + { message: '[plugin test] warnString', code: 'PLUGIN_WARNING', plugin: 'test' } + ], [ 'onLog', 'info', { - message: 'infoLog', + message: '[plugin test] infoLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', code: 'PLUGIN_LOG', plugin: 'test' } ], - ['onLog', 'info', { message: 'infoString', code: 'PLUGIN_LOG', plugin: 'test' }], + [ + 'onLog', + 'info', + { message: '[plugin test] infoString', code: 'PLUGIN_LOG', plugin: 'test' } + ], [ 'onLog', 'debug', { - message: 'debugLog', + message: '[plugin test] debugLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', code: 'PLUGIN_LOG', plugin: 'test' } ], - ['onLog', 'debug', { message: 'debugString', code: 'PLUGIN_LOG', plugin: 'test' }] + [ + 'onLog', + 'debug', + { message: '[plugin test] debugString', code: 'PLUGIN_LOG', plugin: 'test' } + ] ]); }, options: { diff --git a/test/function/samples/logging/log-from-plugin-onwarn/_config.js b/test/function/samples/logging/log-from-plugin-onwarn/_config.js index 92c9de1a2fd..27670d9d0bd 100644 --- a/test/function/samples/logging/log-from-plugin-onwarn/_config.js +++ b/test/function/samples/logging/log-from-plugin-onwarn/_config.js @@ -11,22 +11,22 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ [ 'onwarn', { - message: 'warnLog', + message: '[plugin test] warnLog', pluginCode: 'PLUGIN_CODE', binding: 'foo', code: 'PLUGIN_WARNING', plugin: 'test' } ], - ['onwarn', { message: 'warnString', code: 'PLUGIN_WARNING', plugin: 'test' }], - ['info', '(test plugin) infoLog'], - ['info', '(test plugin) infoString'], - ['debug', '(test plugin) debugLog'], - ['debug', '(test plugin) debugString'] + ['onwarn', { message: '[plugin test] warnString', code: 'PLUGIN_WARNING', plugin: 'test' }], + ['info', '[plugin test] infoLog'], + ['info', '[plugin test] infoString'], + ['debug', '[plugin test] debugLog'], + ['debug', '[plugin test] debugString'] ]); }, options: { diff --git a/test/function/samples/logging/log-from-plugin-options-onlog-onwarn/_config.js b/test/function/samples/logging/log-from-plugin-options-onlog-onwarn/_config.js index 7e1762a9a42..b3709479777 100644 --- a/test/function/samples/logging/log-from-plugin-options-onlog-onwarn/_config.js +++ b/test/function/samples/logging/log-from-plugin-options-onlog-onwarn/_config.js @@ -11,20 +11,28 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['onLog', 'warn', { message: 'warnLog' }], ['onwarn', { message: 'warnLog' }], ['warn', 'warnLog'], [ 'onLog', 'warn', - { message: 'warnLog', plugin: 'fooPlugin', loc: { file: 'fooFile', line: 1, column: 2 } } + { + message: '[plugin fooPlugin] fooFile (1:2): warnLog', + plugin: 'fooPlugin', + loc: { file: 'fooFile', line: 1, column: 2 } + } ], [ 'onwarn', - { message: 'warnLog', plugin: 'fooPlugin', loc: { file: 'fooFile', line: 1, column: 2 } } + { + message: '[plugin fooPlugin] fooFile (1:2): warnLog', + plugin: 'fooPlugin', + loc: { file: 'fooFile', line: 1, column: 2 } + } ], - ['warn', '(fooPlugin plugin) fooFile (1:2) warnLog'], + ['warn', '[plugin fooPlugin] fooFile (1:2): warnLog'], ['onLog', 'warn', { message: 'warnLog=' }], ['onwarn', { message: 'warnLog=' }], ['onLog', 'warn', { message: 'warnLog+=' }], @@ -40,8 +48,8 @@ module.exports = defineTest({ ]); assert.strictEqual(logs[0][2].toString(), 'warnLog'); assert.strictEqual(logs[1][1].toString(), 'warnLog'); - assert.strictEqual(logs[3][2].toString(), '(fooPlugin plugin) fooFile (1:2) warnLog'); - assert.strictEqual(logs[4][1].toString(), '(fooPlugin plugin) fooFile (1:2) warnLog'); + assert.strictEqual(logs[3][2].toString(), '[plugin fooPlugin] fooFile (1:2): warnLog'); + assert.strictEqual(logs[4][1].toString(), '[plugin fooPlugin] fooFile (1:2): warnLog'); }, options: { logLevel: 'debug', diff --git a/test/function/samples/logging/log-from-plugin-options-onlog/_config.js b/test/function/samples/logging/log-from-plugin-options-onlog/_config.js index c133d591664..5da91ed8775 100644 --- a/test/function/samples/logging/log-from-plugin-options-onlog/_config.js +++ b/test/function/samples/logging/log-from-plugin-options-onlog/_config.js @@ -11,15 +11,19 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['onLog', 'warn', { message: 'warnLog' }], ['warn', 'warnLog'], [ 'onLog', 'warn', - { message: 'warnLog', plugin: 'fooPlugin', loc: { file: 'fooFile', line: 1, column: 2 } } + { + message: '[plugin fooPlugin] fooFile (1:2): warnLog', + plugin: 'fooPlugin', + loc: { file: 'fooFile', line: 1, column: 2 } + } ], - ['warn', '(fooPlugin plugin) fooFile (1:2) warnLog'], + ['warn', '[plugin fooPlugin] fooFile (1:2): warnLog'], ['onLog', 'warn', { message: 'warnLog-' }], ['onLog', 'warn', { message: 'warnLog+-' }], ['debug', 'log was replaced'], @@ -31,7 +35,7 @@ module.exports = defineTest({ ['debug', 'debugLog'] ]); assert.strictEqual(logs[0][2].toString(), 'warnLog'); - assert.strictEqual(logs[2][2].toString(), '(fooPlugin plugin) fooFile (1:2) warnLog'); + assert.strictEqual(logs[2][2].toString(), '[plugin fooPlugin] fooFile (1:2): warnLog'); }, options: { logLevel: 'debug', diff --git a/test/function/samples/logging/log-from-plugin-options-onwarn/_config.js b/test/function/samples/logging/log-from-plugin-options-onwarn/_config.js index 7e7c98bf7c2..ebcf3b7b1ea 100644 --- a/test/function/samples/logging/log-from-plugin-options-onwarn/_config.js +++ b/test/function/samples/logging/log-from-plugin-options-onwarn/_config.js @@ -11,14 +11,18 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['onwarn', { message: 'warnLog' }], ['warn', 'warnLog'], [ 'onwarn', - { message: 'warnLog', plugin: 'fooPlugin', loc: { file: 'fooFile', line: 1, column: 2 } } + { + message: '[plugin fooPlugin] fooFile (1:2): warnLog', + plugin: 'fooPlugin', + loc: { file: 'fooFile', line: 1, column: 2 } + } ], - ['warn', '(fooPlugin plugin) fooFile (1:2) warnLog'], + ['warn', '[plugin fooPlugin] fooFile (1:2): warnLog'], ['onwarn', { message: 'warnLog-' }], ['onwarn', { message: 'warnLog+-' }], ['warn', 'log was replaced'], @@ -28,7 +32,7 @@ module.exports = defineTest({ ['debug', 'debugLog'] ]); assert.strictEqual(logs[0][1].toString(), 'warnLog'); - assert.strictEqual(logs[2][1].toString(), '(fooPlugin plugin) fooFile (1:2) warnLog'); + assert.strictEqual(logs[2][1].toString(), '[plugin fooPlugin] fooFile (1:2): warnLog'); }, options: { logLevel: 'debug', diff --git a/test/function/samples/logging/log-from-plugin-options-simple/_config.js b/test/function/samples/logging/log-from-plugin-options-simple/_config.js index 607548a57aa..9cac5dda213 100644 --- a/test/function/samples/logging/log-from-plugin-options-simple/_config.js +++ b/test/function/samples/logging/log-from-plugin-options-simple/_config.js @@ -12,12 +12,12 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['warn', 'warnLog'], ['info', 'infoLog'], ['debug', 'debugLog'] ]); - assert.deepStrictEqual(pluginLogs, [ + assert.deepEqual(pluginLogs, [ ['warn', { message: 'warnLog' }], ['info', { message: 'infoLog' }], ['debug', { message: 'debugLog' }] diff --git a/test/function/samples/logging/log-from-plugin-simple/_config.js b/test/function/samples/logging/log-from-plugin-simple/_config.js index 36998433f25..0e3c4e6463e 100644 --- a/test/function/samples/logging/log-from-plugin-simple/_config.js +++ b/test/function/samples/logging/log-from-plugin-simple/_config.js @@ -11,13 +11,13 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ - ['warn', '(test plugin) warnLog'], - ['warn', '(test plugin) warnString'], - ['info', '(test plugin) infoLog'], - ['info', '(test plugin) infoString'], - ['debug', '(test plugin) debugLog'], - ['debug', '(test plugin) debugString'] + assert.deepEqual(logs, [ + ['warn', '[plugin test] warnLog'], + ['warn', '[plugin test] warnString'], + ['info', '[plugin test] infoLog'], + ['info', '[plugin test] infoString'], + ['debug', '[plugin test] debugLog'], + ['debug', '[plugin test] debugString'] ]); }, options: { diff --git a/test/function/samples/logging/loglevel-debug/_config.js b/test/function/samples/logging/loglevel-debug/_config.js index 46bff1f44d8..60e33b6df2f 100644 --- a/test/function/samples/logging/loglevel-debug/_config.js +++ b/test/function/samples/logging/loglevel-debug/_config.js @@ -16,26 +16,29 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['debug', { message: 'onLog-debug' }], ['console-debug', 'onLogOption-debug'], ['console-info', 'onLogOption-info'], ['console-warn', 'onLogOption-warn'], ['info', { message: 'onLog-info' }], ['warn', { message: 'onLog-warn' }], - ['debug', { message: 'options-debug', code: 'PLUGIN_LOG', plugin: 'test' }], - ['info', { message: 'options-info', code: 'PLUGIN_LOG', plugin: 'test' }], - ['warn', { message: 'options-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], - ['debug', { message: 'buildStart-debug', code: 'PLUGIN_LOG', plugin: 'test' }], - ['info', { message: 'buildStart-info', code: 'PLUGIN_LOG', plugin: 'test' }], - ['warn', { message: 'buildStart-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], + ['debug', { message: '[plugin test] options-debug', code: 'PLUGIN_LOG', plugin: 'test' }], + ['info', { message: '[plugin test] options-info', code: 'PLUGIN_LOG', plugin: 'test' }], + ['warn', { message: '[plugin test] options-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], + ['debug', { message: '[plugin test] buildStart-debug', code: 'PLUGIN_LOG', plugin: 'test' }], + ['info', { message: '[plugin test] buildStart-info', code: 'PLUGIN_LOG', plugin: 'test' }], + [ + 'warn', + { message: '[plugin test] buildStart-warn', code: 'PLUGIN_WARNING', plugin: 'test' } + ], ['debug', { message: 'buildStart-options-debug' }], ['info', { message: 'buildStart-options-info' }], ['warn', { message: 'buildStart-options-warn' }], [ 'debug', { - message: 'transform-debug', + message: '[plugin test] main.js: transform-debug', id: ID_MAIN, hook: 'transform', code: 'PLUGIN_LOG', @@ -45,7 +48,7 @@ module.exports = defineTest({ [ 'info', { - message: 'transform-info', + message: '[plugin test] main.js: transform-info', id: ID_MAIN, hook: 'transform', code: 'PLUGIN_LOG', @@ -55,7 +58,7 @@ module.exports = defineTest({ [ 'warn', { - message: 'transform-warn', + message: '[plugin test] main.js: transform-warn', id: ID_MAIN, hook: 'transform', code: 'PLUGIN_WARNING', @@ -68,7 +71,7 @@ module.exports = defineTest({ code: 'EVAL', id: ID_MAIN, message: - 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + 'main.js (1:0): Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', url: 'https://rollupjs.org/troubleshooting/#avoiding-eval', pos: 0, loc: { diff --git a/test/function/samples/logging/loglevel-info/_config.js b/test/function/samples/logging/loglevel-info/_config.js index 21f2c7daecf..5c492aab3f6 100644 --- a/test/function/samples/logging/loglevel-info/_config.js +++ b/test/function/samples/logging/loglevel-info/_config.js @@ -16,21 +16,24 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['info', { message: 'onLog-info' }], ['console-info', 'onLogOption-info'], ['console-warn', 'onLogOption-warn'], ['warn', { message: 'onLog-warn' }], - ['info', { message: 'options-info', code: 'PLUGIN_LOG', plugin: 'test' }], - ['warn', { message: 'options-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], - ['info', { message: 'buildStart-info', code: 'PLUGIN_LOG', plugin: 'test' }], - ['warn', { message: 'buildStart-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], + ['info', { message: '[plugin test] options-info', code: 'PLUGIN_LOG', plugin: 'test' }], + ['warn', { message: '[plugin test] options-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], + ['info', { message: '[plugin test] buildStart-info', code: 'PLUGIN_LOG', plugin: 'test' }], + [ + 'warn', + { message: '[plugin test] buildStart-warn', code: 'PLUGIN_WARNING', plugin: 'test' } + ], ['info', { message: 'buildStart-options-info' }], ['warn', { message: 'buildStart-options-warn' }], [ 'info', { - message: 'transform-info', + message: '[plugin test] main.js: transform-info', id: ID_MAIN, hook: 'transform', code: 'PLUGIN_LOG', @@ -40,7 +43,7 @@ module.exports = defineTest({ [ 'warn', { - message: 'transform-warn', + message: '[plugin test] main.js: transform-warn', id: ID_MAIN, hook: 'transform', code: 'PLUGIN_WARNING', @@ -53,7 +56,7 @@ module.exports = defineTest({ code: 'EVAL', id: ID_MAIN, message: - 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + 'main.js (1:0): Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', url: 'https://rollupjs.org/troubleshooting/#avoiding-eval', pos: 0, loc: { diff --git a/test/function/samples/logging/loglevel-silent/_config.js b/test/function/samples/logging/loglevel-silent/_config.js index 7377d2c60ed..336869aad86 100644 --- a/test/function/samples/logging/loglevel-silent/_config.js +++ b/test/function/samples/logging/loglevel-silent/_config.js @@ -14,7 +14,7 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, []); + assert.deepEqual(logs, []); }, options: { logLevel: 'silent', diff --git a/test/function/samples/logging/loglevel-warn/_config.js b/test/function/samples/logging/loglevel-warn/_config.js index 425a5ce0fe4..733a645c53e 100644 --- a/test/function/samples/logging/loglevel-warn/_config.js +++ b/test/function/samples/logging/loglevel-warn/_config.js @@ -16,16 +16,19 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, [ + assert.deepEqual(logs, [ ['warn', { message: 'onLog-warn' }], ['console-warn', 'onLogOption-warn'], - ['warn', { message: 'options-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], - ['warn', { message: 'buildStart-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], + ['warn', { message: '[plugin test] options-warn', code: 'PLUGIN_WARNING', plugin: 'test' }], + [ + 'warn', + { message: '[plugin test] buildStart-warn', code: 'PLUGIN_WARNING', plugin: 'test' } + ], ['warn', { message: 'buildStart-options-warn' }], [ 'warn', { - message: 'transform-warn', + message: '[plugin test] main.js: transform-warn', id: ID_MAIN, hook: 'transform', code: 'PLUGIN_WARNING', @@ -38,7 +41,7 @@ module.exports = defineTest({ code: 'EVAL', id: ID_MAIN, message: - 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + 'main.js (1:0): Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', url: 'https://rollupjs.org/troubleshooting/#avoiding-eval', pos: 0, loc: { diff --git a/test/function/samples/logging/no-log-with-position/_config.js b/test/function/samples/logging/no-log-with-position/_config.js index ea383410de6..8dcb2cfabf8 100644 --- a/test/function/samples/logging/no-log-with-position/_config.js +++ b/test/function/samples/logging/no-log-with-position/_config.js @@ -54,11 +54,21 @@ module.exports = defineTest({ message: 'Plugin "test" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.' }, - { level: 'warn', message: 'log-message1', code: 'PLUGIN_WARNING', plugin: 'test' }, - { level: 'warn', message: 'log-message1', code: 'PLUGIN_WARNING', plugin: 'test' }, - { level: 'info', message: 'log-message1', code: 'PLUGIN_LOG', plugin: 'test' }, - { level: 'info', message: 'log-message1', code: 'PLUGIN_LOG', plugin: 'test' }, - { level: 'debug', message: 'log-message1', code: 'PLUGIN_LOG', plugin: 'test' }, - { level: 'debug', message: 'log-message1', code: 'PLUGIN_LOG', plugin: 'test' } + { + level: 'warn', + message: '[plugin test] log-message1', + code: 'PLUGIN_WARNING', + plugin: 'test' + }, + { + level: 'warn', + message: '[plugin test] log-message1', + code: 'PLUGIN_WARNING', + plugin: 'test' + }, + { level: 'info', message: '[plugin test] log-message1', code: 'PLUGIN_LOG', plugin: 'test' }, + { level: 'info', message: '[plugin test] log-message1', code: 'PLUGIN_LOG', plugin: 'test' }, + { level: 'debug', message: '[plugin test] log-message1', code: 'PLUGIN_LOG', plugin: 'test' }, + { level: 'debug', message: '[plugin test] log-message1', code: 'PLUGIN_LOG', plugin: 'test' } ] }); diff --git a/test/function/samples/logging/plugin-order/_config.js b/test/function/samples/logging/plugin-order/_config.js index 284c38029e4..48152211149 100644 --- a/test/function/samples/logging/plugin-order/_config.js +++ b/test/function/samples/logging/plugin-order/_config.js @@ -16,7 +16,7 @@ module.exports = defineTest({ }, onLog(level, log) { logs.push(['first', level, log]); - if (log.message === 'first') { + if (log.message.endsWith('first')) { return false; } } @@ -27,7 +27,7 @@ module.exports = defineTest({ order: 'pre', handler(level, log) { logs.push(['second', level, log]); - if (log.message === 'second') { + if (log.message.endsWith('second')) { return false; } } @@ -39,7 +39,7 @@ module.exports = defineTest({ order: 'post', handler(level, log) { logs.push(['third', level, log]); - if (log.message === 'third') { + if (log.message.endsWith('third')) { return false; } } @@ -48,13 +48,13 @@ module.exports = defineTest({ ] }, after() { - assert.deepStrictEqual(logs, [ - ['second', 'info', { message: 'first', code: 'PLUGIN_LOG', plugin: 'first' }], - ['first', 'info', { message: 'first', code: 'PLUGIN_LOG', plugin: 'first' }], - ['second', 'info', { message: 'second', code: 'PLUGIN_LOG', plugin: 'first' }], - ['second', 'info', { message: 'third', code: 'PLUGIN_LOG', plugin: 'first' }], - ['first', 'info', { message: 'third', code: 'PLUGIN_LOG', plugin: 'first' }], - ['third', 'info', { message: 'third', code: 'PLUGIN_LOG', plugin: 'first' }] + assert.deepEqual(logs, [ + ['second', 'info', { message: '[plugin first] first', code: 'PLUGIN_LOG', plugin: 'first' }], + ['first', 'info', { message: '[plugin first] first', code: 'PLUGIN_LOG', plugin: 'first' }], + ['second', 'info', { message: '[plugin first] second', code: 'PLUGIN_LOG', plugin: 'first' }], + ['second', 'info', { message: '[plugin first] third', code: 'PLUGIN_LOG', plugin: 'first' }], + ['first', 'info', { message: '[plugin first] third', code: 'PLUGIN_LOG', plugin: 'first' }], + ['third', 'info', { message: '[plugin first] third', code: 'PLUGIN_LOG', plugin: 'first' }] ]); }, logs: [] diff --git a/test/function/samples/logging/promote-log-to-error/_config.js b/test/function/samples/logging/promote-log-to-error/_config.js index fe285064e0a..0982a50b859 100644 --- a/test/function/samples/logging/promote-log-to-error/_config.js +++ b/test/function/samples/logging/promote-log-to-error/_config.js @@ -11,7 +11,7 @@ module.exports = defineTest({ }, after() { Object.assign(console, { debug, info, warn }); - assert.deepStrictEqual(logs, []); + assert.deepEqual(logs, []); }, options: { onwarn: null, @@ -31,7 +31,7 @@ module.exports = defineTest({ binding: 'foo', code: 'PLUGIN_ERROR', hook: 'buildStart', - message: 'info becomes error', + message: '[plugin test] info becomes error', plugin: 'test', pluginCode: 'EXTRA_CODE' } diff --git a/test/function/samples/logging/this-error-onlog/_config.js b/test/function/samples/logging/this-error-onlog/_config.js index 1df4b6d0f23..624d6c3b3f2 100644 --- a/test/function/samples/logging/this-error-onlog/_config.js +++ b/test/function/samples/logging/this-error-onlog/_config.js @@ -16,7 +16,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', hook: 'buildStart', - message: 'test log', + message: '[plugin test] test log', plugin: 'test', pluginCode: 'THE_CODE' } diff --git a/test/function/samples/logging/transform-log-with-position/_config.js b/test/function/samples/logging/transform-log-with-position/_config.js index 525d4888a02..804a7af4a77 100644 --- a/test/function/samples/logging/transform-log-with-position/_config.js +++ b/test/function/samples/logging/transform-log-with-position/_config.js @@ -25,7 +25,7 @@ module.exports = defineTest({ logs: [ { level: 'warn', - message: 'warn-message1', + message: '[plugin test] main.js (2:3): warn-message1', pos: 20, loc: { column: 3, @@ -44,7 +44,7 @@ module.exports = defineTest({ }, { level: 'info', - message: 'info-message1', + message: '[plugin test] main.js (2:3): info-message1', pos: 20, loc: { column: 3, @@ -63,7 +63,7 @@ module.exports = defineTest({ }, { level: 'debug', - message: 'debug-message1', + message: '[plugin test] main.js (2:3): debug-message1', pos: 20, loc: { column: 3, @@ -82,7 +82,7 @@ module.exports = defineTest({ }, { level: 'warn', - message: 'warn-message2', + message: '[plugin test] main.js (2:1): warn-message2', loc: { column: 1, file: ID_MAIN, @@ -100,7 +100,7 @@ module.exports = defineTest({ }, { level: 'info', - message: 'info-message2', + message: '[plugin test] main.js (2:1): info-message2', loc: { column: 1, file: ID_MAIN, @@ -118,7 +118,7 @@ module.exports = defineTest({ }, { level: 'debug', - message: 'debug-message2', + message: '[plugin test] main.js (2:1): debug-message2', loc: { column: 1, file: ID_MAIN, @@ -136,7 +136,7 @@ module.exports = defineTest({ }, { level: 'warn', - message: 'warn-message3', + message: '[plugin test] main.js (2:3): warn-message3', pos: 20, loc: { column: 3, @@ -155,7 +155,7 @@ module.exports = defineTest({ }, { level: 'info', - message: 'info-message3', + message: '[plugin test] main.js (2:3): info-message3', pos: 20, loc: { column: 3, @@ -174,7 +174,7 @@ module.exports = defineTest({ }, { level: 'debug', - message: 'debug-message3', + message: '[plugin test] main.js (2:3): debug-message3', pos: 20, loc: { column: 3, diff --git a/test/function/samples/module-level-directive/_config.js b/test/function/samples/module-level-directive/_config.js index 27b8be297fe..bfcff499797 100644 --- a/test/function/samples/module-level-directive/_config.js +++ b/test/function/samples/module-level-directive/_config.js @@ -8,7 +8,7 @@ module.exports = defineTest({ code: 'MODULE_LEVEL_DIRECTIVE', id: ID_MAIN, message: - 'Module level directives cause errors when bundled, "use asm" in "main.js" was ignored.', + 'main.js (1:0): Module level directives cause errors when bundled, "use asm" in "main.js" was ignored.', pos: 0, loc: { column: 0, diff --git a/test/function/samples/namespace-missing-export/_config.js b/test/function/samples/namespace-missing-export/_config.js index 33e436e49fc..fc1445e5424 100644 --- a/test/function/samples/namespace-missing-export/_config.js +++ b/test/function/samples/namespace-missing-export/_config.js @@ -10,7 +10,7 @@ module.exports = defineTest({ code: 'MISSING_EXPORT', exporter: ID_EMPTY, id: ID_MAIN, - message: '"foo" is not exported by "empty.js", imported by "main.js".', + message: 'main.js (3:25): "foo" is not exported by "empty.js", imported by "main.js".', url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module', pos: 61, loc: { diff --git a/test/function/samples/namespace-reassign-import-fails/_config.js b/test/function/samples/namespace-reassign-import-fails/_config.js index fccf0274364..b3338ac86b2 100644 --- a/test/function/samples/namespace-reassign-import-fails/_config.js +++ b/test/function/samples/namespace-reassign-import-fails/_config.js @@ -16,7 +16,7 @@ module.exports = defineTest({ code: 'MISSING_EXPORT', exporter: ID_FOO, id: ID_MAIN, - message: '"bar" is not exported by "foo.js", imported by "main.js".', + message: 'main.js (4:4): "bar" is not exported by "foo.js", imported by "main.js".', url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module', pos: 48, loc: { @@ -32,7 +32,7 @@ module.exports = defineTest({ }, { code: 'ILLEGAL_REASSIGNMENT', - message: 'Illegal reassignment of import "exp" in "main.js".', + message: 'main.js (3:0): Illegal reassignment of import "exp" in "main.js".', id: ID_MAIN, pos: 31, loc: { @@ -49,7 +49,7 @@ module.exports = defineTest({ }, { code: 'ILLEGAL_REASSIGNMENT', - message: 'Illegal reassignment of import "exp" in "main.js".', + message: 'main.js (4:0): Illegal reassignment of import "exp" in "main.js".', id: ID_MAIN, pos: 44, loc: { diff --git a/test/function/samples/namespace-update-import-fails/_config.js b/test/function/samples/namespace-update-import-fails/_config.js index d4c95497bb9..351f22e75b8 100644 --- a/test/function/samples/namespace-update-import-fails/_config.js +++ b/test/function/samples/namespace-update-import-fails/_config.js @@ -11,7 +11,7 @@ module.exports = defineTest({ warnings: [ { code: 'ILLEGAL_REASSIGNMENT', - message: 'Illegal reassignment of import "exp" in "main.js".', + message: 'main.js (3:0): Illegal reassignment of import "exp" in "main.js".', id: ID_MAIN, pos: 31, loc: { diff --git a/test/function/samples/non-function-hook-async/_config.js b/test/function/samples/non-function-hook-async/_config.js index 615a143ee4e..af2e8adf801 100644 --- a/test/function/samples/non-function-hook-async/_config.js +++ b/test/function/samples/non-function-hook-async/_config.js @@ -7,7 +7,7 @@ module.exports = defineTest({ code: 'INVALID_PLUGIN_HOOK', hook: 'resolveId', message: - 'Error running plugin hook "resolveId" for plugin "at position 1", expected a function hook or an object with a "handler" function.', + '[plugin at position 1] Error running plugin hook "resolveId" for plugin "at position 1", expected a function hook or an object with a "handler" function.', plugin: 'at position 1' } }); diff --git a/test/function/samples/non-function-hook-sync/_config.js b/test/function/samples/non-function-hook-sync/_config.js index 3c7e75e4c7b..5e0e82a45c7 100644 --- a/test/function/samples/non-function-hook-sync/_config.js +++ b/test/function/samples/non-function-hook-sync/_config.js @@ -11,7 +11,7 @@ module.exports = defineTest({ code: 'INVALID_PLUGIN_HOOK', hook: 'outputOptions', message: - 'Error running plugin hook "outputOptions" for plugin "at position 1", expected a function hook or an object with a "handler" function.', + '[plugin at position 1] Error running plugin hook "outputOptions" for plugin "at position 1", expected a function hook or an object with a "handler" function.', plugin: 'at position 1' } }); diff --git a/test/function/samples/plugin-error-loc-instead-pos/_config.js b/test/function/samples/plugin-error-loc-instead-pos/_config.js index 8619397ece3..dca00e4a3e4 100644 --- a/test/function/samples/plugin-error-loc-instead-pos/_config.js +++ b/test/function/samples/plugin-error-loc-instead-pos/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] main.js (1:22): nope', hook: 'transform', id: path.join(__dirname, 'main.js'), watchFiles: [path.join(__dirname, 'main.js')], diff --git a/test/function/samples/plugin-error/buildEnd/_config.js b/test/function/samples/plugin-error/buildEnd/_config.js index 327db966a4a..aa462c719df 100644 --- a/test/function/samples/plugin-error/buildEnd/_config.js +++ b/test/function/samples/plugin-error/buildEnd/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'buildEnd' } }); diff --git a/test/function/samples/plugin-error/buildStart/_config.js b/test/function/samples/plugin-error/buildStart/_config.js index 6ea085f42fc..fcc14543b60 100644 --- a/test/function/samples/plugin-error/buildStart/_config.js +++ b/test/function/samples/plugin-error/buildStart/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'buildStart' } }); diff --git a/test/function/samples/plugin-error/generateBundle/_config.js b/test/function/samples/plugin-error/generateBundle/_config.js index 7e17c2b92aa..73180d5547f 100644 --- a/test/function/samples/plugin-error/generateBundle/_config.js +++ b/test/function/samples/plugin-error/generateBundle/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ generateError: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'generateBundle' } }); diff --git a/test/function/samples/plugin-error/load/_config.js b/test/function/samples/plugin-error/load/_config.js index a5de941a73e..5b25cb5d1cf 100644 --- a/test/function/samples/plugin-error/load/_config.js +++ b/test/function/samples/plugin-error/load/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: `Could not load ${path.join(__dirname, 'main.js')}: nope`, + message: `Could not load ${path.join(__dirname, 'main.js')}: [plugin test] nope`, hook: 'load' } }); diff --git a/test/function/samples/plugin-error/renderChunk/_config.js b/test/function/samples/plugin-error/renderChunk/_config.js index dcc254529b6..31670e2317a 100644 --- a/test/function/samples/plugin-error/renderChunk/_config.js +++ b/test/function/samples/plugin-error/renderChunk/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ generateError: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'renderChunk' } }); diff --git a/test/function/samples/plugin-error/renderStart/_config.js b/test/function/samples/plugin-error/renderStart/_config.js index 4756298ddb4..35f6ed4ea47 100644 --- a/test/function/samples/plugin-error/renderStart/_config.js +++ b/test/function/samples/plugin-error/renderStart/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ generateError: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'renderStart' } }); diff --git a/test/function/samples/plugin-error/resolveId/_config.js b/test/function/samples/plugin-error/resolveId/_config.js index 9b3390ca35c..7c85f429f58 100644 --- a/test/function/samples/plugin-error/resolveId/_config.js +++ b/test/function/samples/plugin-error/resolveId/_config.js @@ -13,7 +13,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] nope', hook: 'resolveId' } }); diff --git a/test/function/samples/plugin-error/transform/_config.js b/test/function/samples/plugin-error/transform/_config.js index 1c893155d14..f31ea7dc464 100644 --- a/test/function/samples/plugin-error/transform/_config.js +++ b/test/function/samples/plugin-error/transform/_config.js @@ -15,7 +15,7 @@ module.exports = defineTest({ error: { code: 'PLUGIN_ERROR', plugin: 'test', - message: 'nope', + message: '[plugin test] main.js (1:22): nope', hook: 'transform', id: path.join(__dirname, 'main.js'), watchFiles: [path.join(__dirname, 'main.js')], diff --git a/test/function/samples/plugin-warn-loc-instead-pos/_config.js b/test/function/samples/plugin-warn-loc-instead-pos/_config.js index 1fe4904b40c..7f864ff3008 100644 --- a/test/function/samples/plugin-warn-loc-instead-pos/_config.js +++ b/test/function/samples/plugin-warn-loc-instead-pos/_config.js @@ -19,7 +19,7 @@ module.exports = defineTest({ id: path.join(__dirname, 'main.js'), plugin: 'test', hook: 'transform', - message: 'foo', + message: '[plugin test] main.js (1:22): foo', loc: { file: path.join(__dirname, 'main.js'), line: 1, diff --git a/test/function/samples/plugin-warn/_config.js b/test/function/samples/plugin-warn/_config.js index 32c110eadc7..ffcddb1eb61 100644 --- a/test/function/samples/plugin-warn/_config.js +++ b/test/function/samples/plugin-warn/_config.js @@ -20,7 +20,7 @@ module.exports = defineTest({ id: path.join(__dirname, 'main.js'), hook: 'transform', plugin: 'test', - message: 'foo', + message: '[plugin test] main.js: foo', pluginCode: 'CODE' }, { @@ -28,7 +28,7 @@ module.exports = defineTest({ id: path.join(__dirname, 'main.js'), plugin: 'test', hook: 'transform', - message: 'bar', + message: '[plugin test] main.js (1:22): bar', pos: 22, loc: { file: path.join(__dirname, 'main.js'), diff --git a/test/function/samples/reexport-missing-error/_config.js b/test/function/samples/reexport-missing-error/_config.js index 923cf1477ca..f678eaf6783 100644 --- a/test/function/samples/reexport-missing-error/_config.js +++ b/test/function/samples/reexport-missing-error/_config.js @@ -20,6 +20,6 @@ module.exports = defineTest({ 1: export { foo as bar } from './empty.js'; ^`, watchFiles: [ID_EMPTY, ID_MAIN], - message: '"foo" is not exported by "empty.js", imported by "main.js".' + message: 'main.js (1:9): "foo" is not exported by "empty.js", imported by "main.js".' } }); diff --git a/test/function/samples/transform-without-sourcemap-render-chunk/_config.js b/test/function/samples/transform-without-sourcemap-render-chunk/_config.js index 46076d52430..a6c572f3156 100644 --- a/test/function/samples/transform-without-sourcemap-render-chunk/_config.js +++ b/test/function/samples/transform-without-sourcemap-render-chunk/_config.js @@ -24,7 +24,7 @@ module.exports = defineTest({ { 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: `[plugin fake plugin 1] 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/troubleshooting/#warning-sourcemap-is-likely-to-be-incorrect` } ] diff --git a/test/function/samples/validate-output/_config.js b/test/function/samples/validate-output/_config.js index 4cb4989a4ec..39f99759b4d 100644 --- a/test/function/samples/validate-output/_config.js +++ b/test/function/samples/validate-output/_config.js @@ -11,7 +11,7 @@ module.exports = defineTest({ }, generateError: { code: 'CHUNK_INVALID', - message: 'Chunk "main.js" is not valid JavaScript: Unterminated block comment.', + message: 'main.js (5:0): Chunk "main.js" is not valid JavaScript: Unterminated block comment.', frame: ` 3: throw new Error('Not executed'); 4: diff --git a/test/function/samples/warn-misplaced-annotations/_config.js b/test/function/samples/warn-misplaced-annotations/_config.js index 8a84d70a3c4..5b03c29402d 100644 --- a/test/function/samples/warn-misplaced-annotations/_config.js +++ b/test/function/samples/warn-misplaced-annotations/_config.js @@ -8,7 +8,7 @@ module.exports = defineTest({ code: 'INVALID_ANNOTATION', id: ID_MAIN, message: - 'A comment\n\n"/*@__NO_SIDE_EFFECTS__*/"\n\nin "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.', + 'main.js (2:0): A comment\n\n"/*@__NO_SIDE_EFFECTS__*/"\n\nin "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.', url: 'https://rollupjs.org/configuration-options/#no-side-effects', pos: 45, loc: { @@ -27,7 +27,7 @@ module.exports = defineTest({ code: 'INVALID_ANNOTATION', id: ID_MAIN, message: - 'A comment\n\n"/*@__NO_SIDE_EFFECTS__*/"\n\nin "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.', + 'main.js (4:0): A comment\n\n"/*@__NO_SIDE_EFFECTS__*/"\n\nin "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.', url: 'https://rollupjs.org/configuration-options/#no-side-effects', pos: 113, loc: { @@ -45,7 +45,7 @@ module.exports = defineTest({ code: 'INVALID_ANNOTATION', id: ID_MAIN, message: - 'A comment\n\n"/*@__PURE__*/"\n\nin "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.', + 'main.js (1:0): A comment\n\n"/*@__PURE__*/"\n\nin "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.', url: 'https://rollupjs.org/configuration-options/#pure', pos: 0, loc: { diff --git a/test/function/samples/warn-on-eval/_config.js b/test/function/samples/warn-on-eval/_config.js index e6b40ffb9f8..8c87a38cdc4 100644 --- a/test/function/samples/warn-on-eval/_config.js +++ b/test/function/samples/warn-on-eval/_config.js @@ -8,7 +8,7 @@ module.exports = defineTest({ code: 'EVAL', id: ID_MAIN, message: - 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + 'main.js (1:13): Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', url: 'https://rollupjs.org/troubleshooting/#avoiding-eval', pos: 13, loc: { diff --git a/test/function/samples/warn-on-top-level-this/_config.js b/test/function/samples/warn-on-top-level-this/_config.js index 96c0ac20b27..14eb9a4f55b 100644 --- a/test/function/samples/warn-on-top-level-this/_config.js +++ b/test/function/samples/warn-on-top-level-this/_config.js @@ -7,7 +7,7 @@ module.exports = defineTest({ { code: 'THIS_IS_UNDEFINED', id: path.join(__dirname, 'main.js'), - message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`, + message: `main.js (3:0): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`, pos: 81, loc: { file: path.join(__dirname, 'main.js'), diff --git a/test/function/samples/warn-on-unused-missing-imports/_config.js b/test/function/samples/warn-on-unused-missing-imports/_config.js index 89e459c4860..49557fdf7c7 100644 --- a/test/function/samples/warn-on-unused-missing-imports/_config.js +++ b/test/function/samples/warn-on-unused-missing-imports/_config.js @@ -10,7 +10,7 @@ module.exports = defineTest({ code: 'MISSING_EXPORT', exporter: ID_FOO, id: ID_MAIN, - message: '"b" is not exported by "foo.js", imported by "main.js".', + message: 'main.js (1:12): "b" is not exported by "foo.js", imported by "main.js".', url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module', pos: 12, loc: { diff --git a/test/function/samples/warning-incorrect-sourcemap-location/_config.js b/test/function/samples/warning-incorrect-sourcemap-location/_config.js index fde30b21181..092bfeb0a7d 100644 --- a/test/function/samples/warning-incorrect-sourcemap-location/_config.js +++ b/test/function/samples/warning-incorrect-sourcemap-location/_config.js @@ -26,7 +26,8 @@ module.exports = defineTest({ file: ID_MAIN, line: 12 }, - message: '"NON_EXISTENT" is not exported by "constants.js", imported by "main.js".', + message: + 'main.js (12:15): "NON_EXISTENT" is not exported by "constants.js", imported by "main.js".', pos: 111, url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module' } diff --git a/test/function/samples/warning-low-resolution-location/_config.js b/test/function/samples/warning-low-resolution-location/_config.js index 885a9df7b2f..fb233d2ac4d 100644 --- a/test/function/samples/warning-low-resolution-location/_config.js +++ b/test/function/samples/warning-low-resolution-location/_config.js @@ -34,7 +34,7 @@ module.exports = defineTest({ line: 1 }, message: - "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", + "main.js (1:0): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", pos: 15, url: 'https://rollupjs.org/troubleshooting/#error-this-is-undefined' } diff --git a/test/function/samples/warnings-to-string/_config.js b/test/function/samples/warnings-to-string/_config.js index 678c9739f19..cdad433728a 100644 --- a/test/function/samples/warnings-to-string/_config.js +++ b/test/function/samples/warnings-to-string/_config.js @@ -14,7 +14,7 @@ module.exports = defineTest({ }, warnings(warnings) { assert.deepStrictEqual(warnings.map(String), [ - '(test-plugin plugin) main.js (1:6) This might be removed', + '[plugin test-plugin] main.js (1:6): This might be removed', 'Generated an empty chunk: "main".' ]); } diff --git a/test/hooks/index.js b/test/hooks/index.js index 5e8d5ac737b..3ac156d9e7d 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -2,7 +2,7 @@ const assert = require('node:assert'); const path = require('node:path'); const { outputFile, readdir, remove } = require('fs-extra'); /** - * @type {import('../../src/rollup/types')} Rollup + * @type {import("../../src/rollup/types")} Rollup */ const rollup = require('../../dist/rollup.js'); const { loader, wait } = require('../utils.js'); @@ -96,10 +96,10 @@ describe('hooks', () => { input: 'input', onwarn(warning) { if (callCnt === 0) { - assert.strictEqual(warning.message, 'build start'); + assert.strictEqual(warning.message, '[plugin at position 2] build start'); callCnt++; } else if (callCnt === 1) { - assert.strictEqual(warning.message, 'build end'); + assert.strictEqual(warning.message, '[plugin at position 2] build end'); callCnt++; } }, @@ -132,7 +132,7 @@ describe('hooks', () => { this.error('build start error'); }, buildEnd(error) { - assert.strictEqual(error.message, 'build start error'); + assert.strictEqual(error.message, '[plugin at position 2] build start error'); handledError = true; } } @@ -140,7 +140,7 @@ describe('hooks', () => { }) .catch(error => { assert.ok(handledError); - assert.strictEqual(error.message, 'build start error'); + assert.strictEqual(error.message, '[plugin at position 2] build start error'); }) .then(() => { assert.ok(handledError); @@ -1024,7 +1024,7 @@ describe('hooks', () => { }) .then(bundle => bundle.close()) .catch(error => { - assert.strictEqual(error.message, 'close bundle error'); + assert.strictEqual(error.message, '[plugin at position 2] close bundle error'); handledError = true; }) .then(() => { @@ -1080,6 +1080,7 @@ describe('hooks', () => { addPlugin('post'); addPlugin('pre'); addPlugin(); + function addPlugin(order) { const name = `${order}-${plugins.length}`; const plugin = { name }; diff --git a/test/misc/sanity-checks.js b/test/misc/sanity-checks.js index 0170ac4b9b6..49403573df4 100644 --- a/test/misc/sanity-checks.js +++ b/test/misc/sanity-checks.js @@ -33,7 +33,7 @@ describe('sanity checks', () => { assert.equal(parameters[0].code, 'EVAL'); assert.equal( parameters[0].message, - 'Use of eval in "x" is strongly discouraged as it poses security risks and may cause issues with minification.' + 'x (1:0): Use of eval in "x" is strongly discouraged as it poses security risks and may cause issues with minification.' ); assert.equal(typeof parameters[1], 'function'); }); diff --git a/test/watch/index.js b/test/watch/index.js index a8a6ed18077..9b2669d60a9 100644 --- a/test/watch/index.js +++ b/test/watch/index.js @@ -1,27 +1,37 @@ const assert = require('node:assert'); const { existsSync, readdirSync, readFileSync, rmSync, unlinkSync } = require('node:fs'); -const { rm, unlink, writeFile } = require('node:fs/promises'); -const { resolve } = require('node:path'); -const { chdir, cwd, hrtime } = require('node:process'); +const { rm, unlink, writeFile, mkdir } = require('node:fs/promises'); +const { join, resolve } = require('node:path'); +const { hrtime } = require('node:process'); const { copy } = require('fs-extra'); /** - * @type {import('../../src/rollup/types')} Rollup + * @type {import("../../src/rollup/types")} Rollup */ const rollup = require('../../dist/rollup'); const { atomicWriteFileSync, wait, withTimeout } = require('../utils'); -describe('rollup.watch', () => { +const SAMPLES_DIR = join(__dirname, 'samples'); +const TEMP_DIR = join(__dirname, '../_tmp'); +const INPUT_DIR = join(TEMP_DIR, 'input'); +const ENTRY_FILE = join(INPUT_DIR, 'main.js'); +const OUTPUT_DIR = join(TEMP_DIR, 'output'); +const BUNDLE_FILE = join(OUTPUT_DIR, 'bundle.js'); + +describe('rollup.watch', function () { + this.timeout(40_000); let watcher; - beforeEach(() => { - chdir(cwd()); - return rm('test/_tmp', { + beforeEach(async () => { + process.chdir(__dirname); + await rm(TEMP_DIR, { force: true, recursive: true }); + await mkdir(INPUT_DIR, { recursive: true }); + process.chdir(INPUT_DIR); }); - afterEach(() => { + afterEach(async () => { if (watcher) { watcher.close(); watcher = null; @@ -31,9 +41,9 @@ describe('rollup.watch', () => { it('watches a file and triggers reruns if necessary', async () => { let triggerRestart = false; - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { name: 'test-plugin', options() { @@ -44,14 +54,14 @@ describe('rollup.watch', () => { if (triggerRestart) { triggerRestart = false; await wait(100); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 44;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 44;'); await wait(100); return code; } } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -62,9 +72,9 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); triggerRestart = true; - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', @@ -75,7 +85,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 44); + assert.strictEqual(run(BUNDLE_FILE), 44); } ]); }); @@ -84,14 +94,14 @@ describe('rollup.watch', () => { let run = 0; const events = new Set(); - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { async writeBundle() { if (run++ === 0) { await wait(100); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 48;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 48;'); await wait(100); } if (run === 2) { @@ -100,7 +110,7 @@ describe('rollup.watch', () => { } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -134,9 +144,9 @@ describe('rollup.watch', () => { }); it('does not fail for virtual files', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { resolveId(id) { if (id === 'virtual') { @@ -150,7 +160,7 @@ describe('rollup.watch', () => { } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -161,9 +171,9 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); atomicWriteFileSync( - 'test/_tmp/input/main.js', + ENTRY_FILE, "import {value} from 'virtual';\nexport default value + 1;" ); }, @@ -172,26 +182,26 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('passes file events to the watchChange plugin hook once for each change', async () => { let watchChangeCnt = 0; - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); await wait(100); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, plugins: { watchChange(id) { watchChangeCnt++; - assert.strictEqual(id, resolve('test/_tmp/input/main.js')); + assert.strictEqual(id, ENTRY_FILE); } } }); @@ -203,50 +213,50 @@ describe('rollup.watch', () => { 'END', () => { watchChangeCnt = 0; - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); assert.strictEqual(watchChangeCnt, 1); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); assert.strictEqual(watchChangeCnt, 2); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); assert.strictEqual(watchChangeCnt, 3); } ]); }); it('passes change parameter to the watchChange plugin hook', async () => { - const WATCHED_ID = resolve('test/_tmp/input/watched'); + const WATCHED_ID = join(INPUT_DIR, 'watched'); const events = []; let ids; - const expectedIds = [WATCHED_ID, resolve('test/_tmp/input/main.js')]; - await copy('test/watch/samples/watch-files', 'test/_tmp/input'); + const expectedIds = [WATCHED_ID, ENTRY_FILE]; + await copy(join(SAMPLES_DIR, 'watch-files'), INPUT_DIR); await unlink(WATCHED_ID); await wait(100); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -273,7 +283,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); assert.deepStrictEqual(events, []); assert.deepStrictEqual(ids, expectedIds); atomicWriteFileSync(WATCHED_ID, 'first'); @@ -283,7 +293,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); assert.deepStrictEqual(events, ['create']); assert.deepStrictEqual(ids, expectedIds); atomicWriteFileSync(WATCHED_ID, 'first'); @@ -293,7 +303,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); assert.deepStrictEqual(events, ['create', 'update']); assert.deepStrictEqual(ids, expectedIds); unlinkSync(WATCHED_ID); @@ -303,7 +313,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); assert.deepStrictEqual(events, ['create', 'update', 'delete']); assert.deepStrictEqual(ids, expectedIds); } @@ -311,15 +321,15 @@ describe('rollup.watch', () => { }); it('correctly rewrites change event during build delay', async () => { - const WATCHED_ID = resolve('test/_tmp/input/watched'); - const MAIN_ID = resolve('test/_tmp/input/main.js'); + const WATCHED_ID = join(INPUT_DIR, 'watched'); + const MAIN_ID = ENTRY_FILE; let lastEvent = null; - await copy('test/watch/samples/watch-files', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'watch-files'), INPUT_DIR); await wait(100); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -390,11 +400,11 @@ describe('rollup.watch', () => { let calls = 0; let context1; let context2; - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -427,7 +437,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); assert.ok(context1); assert.ok(context2); watcher.once('close', () => { @@ -439,11 +449,11 @@ describe('rollup.watch', () => { }); it('watches a file in code-splitting mode', async () => { - await copy('test/watch/samples/code-splitting', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'code-splitting'), INPUT_DIR); watcher = rollup.watch({ - input: ['test/_tmp/input/main1.js', 'test/_tmp/input/main2.js'], + input: [join(INPUT_DIR, 'main1.js'), join(INPUT_DIR, 'main2.js')], output: { - dir: 'test/_tmp/output', + dir: OUTPUT_DIR, format: 'cjs', exports: 'auto' } @@ -454,30 +464,30 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/main1.js'), 21); - assert.strictEqual(run('../_tmp/output/main2.js'), 42); - atomicWriteFileSync('test/_tmp/input/shared.js', 'export const value = 22;'); + assert.strictEqual(run(join(OUTPUT_DIR, 'main1.js')), 21); + assert.strictEqual(run(join(OUTPUT_DIR, 'main2.js')), 42); + atomicWriteFileSync(join(INPUT_DIR, 'shared.js'), 'export const value = 22;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/main1.js'), 22); - assert.strictEqual(run('../_tmp/output/main2.js'), 44); + assert.strictEqual(run(join(OUTPUT_DIR, 'main1.js')), 22); + assert.strictEqual(run(join(OUTPUT_DIR, 'main2.js')), 44); } ]); }); it('watches a file in code-splitting mode with an input object', async () => { - await copy('test/watch/samples/code-splitting', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'code-splitting'), INPUT_DIR); watcher = rollup.watch({ input: { - _main_1: 'test/_tmp/input/main1.js', - 'subfolder/_main_2': 'test/_tmp/input/main2.js' + _main_1: join(INPUT_DIR, 'main1.js'), + 'subfolder/_main_2': join(INPUT_DIR, 'main2.js') }, output: { - dir: 'test/_tmp/output', + dir: OUTPUT_DIR, format: 'cjs', exports: 'auto' } @@ -488,27 +498,27 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/_main_1.js'), 21); - assert.strictEqual(run('../_tmp/output/subfolder/_main_2.js'), 42); - atomicWriteFileSync('test/_tmp/input/shared.js', 'export const value = 22;'); + assert.strictEqual(run(join(OUTPUT_DIR, '_main_1.js')), 21); + assert.strictEqual(run(join(OUTPUT_DIR, 'subfolder/_main_2.js')), 42); + atomicWriteFileSync(join(INPUT_DIR, 'shared.js'), 'export const value = 22;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/_main_1.js'), 22); - assert.strictEqual(run('../_tmp/output/subfolder/_main_2.js'), 44); + assert.strictEqual(run(join(OUTPUT_DIR, '_main_1.js')), 22); + assert.strictEqual(run(join(OUTPUT_DIR, 'subfolder/_main_2.js')), 44); } ]); }); it('recovers from an error', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -519,32 +529,32 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', 'export nope;'); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, 'export nope;'); }, 'START', 'BUNDLE_START', - "ERROR:Expected '{', got 'nope'", + "ERROR:main.js (1:7): Expected '{', got 'nope'", 'END', () => { - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('recovers from an error on initial build', async () => { - await copy('test/watch/samples/error', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'error'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -552,36 +562,36 @@ describe('rollup.watch', () => { return sequence(watcher, [ 'START', 'BUNDLE_START', - 'ERROR:Expression expected', + 'ERROR:main.js (2:0): Expression expected', 'END', () => { - assert.strictEqual(existsSync('../_tmp/output/bundle.js'), false); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + assert.strictEqual(existsSync(BUNDLE_FILE), false); + atomicWriteFileSync(ENTRY_FILE, '' + 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('recovers from a plugin error on initial build', async () => { - let count = 0; - await copy('test/watch/samples/basic', 'test/_tmp/input'); + let error = true; + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { transform() { - if (count++ === 0) { - this.error('The first run failed, try again.'); + if (error) { + this.error('This run failed, try again.'); } } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -589,27 +599,28 @@ describe('rollup.watch', () => { return sequence(watcher, [ 'START', 'BUNDLE_START', - 'ERROR:The first run failed, try again.', + 'ERROR:[plugin at position 1] main.js: This run failed, try again.', 'END', () => { - assert.strictEqual(existsSync('../_tmp/output/bundle.js'), false); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + error = false; + assert.strictEqual(existsSync(BUNDLE_FILE), false); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('awaits and recovers from a plugin error in the watchChange hook', async () => { let fail = true; - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { async watchChange() { await wait(300); @@ -619,7 +630,7 @@ describe('rollup.watch', () => { } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -630,31 +641,31 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 21;'); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, 'export default 21;'); }, - 'ERROR:Failed in watchChange', + 'ERROR:[plugin at position 1] Failed in watchChange', 'END', () => { fail = false; - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('recovers from an error even when erroring entry was "renamed" (#38)', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -665,34 +676,34 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - unlinkSync('test/_tmp/input/main.js'); - atomicWriteFileSync('test/_tmp/input/main.js', 'export nope;'); + assert.strictEqual(run(BUNDLE_FILE), 42); + unlinkSync(ENTRY_FILE); + atomicWriteFileSync(ENTRY_FILE, 'export nope;'); }, 'START', 'BUNDLE_START', - "ERROR:Expected '{', got 'nope'", + "ERROR:main.js (1:7): Expected '{', got 'nope'", 'END', () => { - unlinkSync('test/_tmp/input/main.js'); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + unlinkSync(ENTRY_FILE); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('recovers from an error even when erroring dependency was "renamed" (#38)', async () => { - await copy('test/watch/samples/dependency', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'dependency'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -703,39 +714,39 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); - unlinkSync('test/_tmp/input/dep.js'); - atomicWriteFileSync('test/_tmp/input/dep.js', 'export nope;'); + assert.strictEqual(run(BUNDLE_FILE), 43); + unlinkSync(join(INPUT_DIR, 'dep.js')); + atomicWriteFileSync(join(INPUT_DIR, 'dep.js'), 'export nope;'); }, 'START', 'BUNDLE_START', - "ERROR:Expected '{', got 'nope'", + "ERROR:dep.js (1:7): Expected '{', got 'nope'", 'END', () => { - unlinkSync('test/_tmp/input/dep.js'); - atomicWriteFileSync('test/_tmp/input/dep.js', 'export const value = 43;'); + unlinkSync(join(INPUT_DIR, 'dep.js')); + atomicWriteFileSync(join(INPUT_DIR, 'dep.js'), 'export const value = 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 44); + assert.strictEqual(run(BUNDLE_FILE), 44); } ]); }); it('handles closing the watcher during a build', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { load() { watcher.close(); } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -746,7 +757,7 @@ describe('rollup.watch', () => { 'START', 'BUNDLE_START', async () => { - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 44;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 44;'); await wait(400); assert.deepStrictEqual(events, ['START', 'BUNDLE_START']); } @@ -754,16 +765,16 @@ describe('rollup.watch', () => { }); it('handles closing the watcher during a build even if an error occurred', async () => { - await copy('test/watch/samples/error', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'error'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { load() { watcher.close(); } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -774,7 +785,7 @@ describe('rollup.watch', () => { 'START', 'BUNDLE_START', async () => { - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 44;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 44;'); await wait(400); assert.deepStrictEqual(events, ['START', 'BUNDLE_START']); } @@ -782,11 +793,11 @@ describe('rollup.watch', () => { }); it('stops watching files that are no longer part of the graph', async () => { - await copy('test/watch/samples/dependency', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'dependency'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -797,20 +808,20 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 42;'); + assert.strictEqual(run(BUNDLE_FILE), 43); + atomicWriteFileSync(ENTRY_FILE, 'export default 42;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', async () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); let unexpectedEvent = false; watcher.once('event', event => { unexpectedEvent = event; }); - atomicWriteFileSync('test/_tmp/input/dep.js', '= invalid'); + atomicWriteFileSync(join(INPUT_DIR, 'dep.js'), '= invalid'); await wait(400); assert.strictEqual(unexpectedEvent, false); } @@ -818,11 +829,11 @@ describe('rollup.watch', () => { }); it('refuses to watch the output file (#15)', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -833,37 +844,37 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', `import '../output/bundle.js'`); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, `import '../output/bundle.js'`); }, 'START', 'BUNDLE_START', 'ERROR:Cannot import the generated bundle', 'END', () => { - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); it('ignores files that are not specified in options.watch.include, if given', async () => { - await copy('test/watch/samples/ignored', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'ignored'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, watch: { - include: ['test/_tmp/input/+(main|foo).js'] + include: [join(INPUT_DIR, '+(main|foo).js')] } }); return sequence(watcher, [ @@ -872,18 +883,18 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.deepStrictEqual(run('../_tmp/output/bundle.js'), { + assert.deepStrictEqual(run(BUNDLE_FILE), { foo: 'foo-1', bar: 'bar-1' }); - atomicWriteFileSync('test/_tmp/input/foo.js', `export default 'foo-2';`); + atomicWriteFileSync(join(INPUT_DIR, 'foo.js'), `export default 'foo-2';`); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', async () => { - assert.deepStrictEqual(run('../_tmp/output/bundle.js'), { + assert.deepStrictEqual(run(BUNDLE_FILE), { foo: 'foo-2', bar: 'bar-1' }); @@ -891,9 +902,9 @@ describe('rollup.watch', () => { watcher.once('event', event => { unexpectedEvent = event; }); - atomicWriteFileSync('test/_tmp/input/bar.js', "export default 'bar-2';"); + atomicWriteFileSync(join(INPUT_DIR, 'bar.js'), "export default 'bar-2';"); await wait(400); - assert.deepStrictEqual(run('../_tmp/output/bundle.js'), { + assert.deepStrictEqual(run(BUNDLE_FILE), { foo: 'foo-2', bar: 'bar-1' }); @@ -903,16 +914,16 @@ describe('rollup.watch', () => { }); it('ignores files that are specified in options.watch.exclude, if given', async () => { - await copy('test/watch/samples/ignored', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'ignored'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, watch: { - exclude: ['test/_tmp/input/bar.js'] + exclude: [join(INPUT_DIR, 'bar.js')] } }); return sequence(watcher, [ @@ -921,18 +932,18 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.deepStrictEqual(run('../_tmp/output/bundle.js'), { + assert.deepStrictEqual(run(BUNDLE_FILE), { foo: 'foo-1', bar: 'bar-1' }); - atomicWriteFileSync('test/_tmp/input/foo.js', `export default 'foo-2';`); + atomicWriteFileSync(join(INPUT_DIR, 'foo.js'), `export default 'foo-2';`); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', async () => { - assert.deepStrictEqual(run('../_tmp/output/bundle.js'), { + assert.deepStrictEqual(run(BUNDLE_FILE), { foo: 'foo-2', bar: 'bar-1' }); @@ -940,9 +951,9 @@ describe('rollup.watch', () => { watcher.once('event', event => { unexpectedEvent = event; }); - atomicWriteFileSync('test/_tmp/input/bar.js', "export default 'bar-2';"); + atomicWriteFileSync(join(INPUT_DIR, 'bar.js'), "export default 'bar-2';"); await wait(400); - assert.deepStrictEqual(run('../_tmp/output/bundle.js'), { + assert.deepStrictEqual(run(BUNDLE_FILE), { foo: 'foo-2', bar: 'bar-1' }); @@ -952,21 +963,21 @@ describe('rollup.watch', () => { }); it('only rebuilds the appropriate configs', async () => { - await copy('test/watch/samples/multiple', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'multiple'), INPUT_DIR); await wait(100); watcher = rollup.watch([ { - input: 'test/_tmp/input/main1.js', + input: join(INPUT_DIR, 'main1.js'), output: { - file: 'test/_tmp/output/bundle1.js', + file: join(OUTPUT_DIR, 'bundle1.js'), format: 'cjs', exports: 'auto' } }, { - input: 'test/_tmp/input/main2.js', + input: join(INPUT_DIR, 'main2.js'), output: { - file: 'test/_tmp/output/bundle2.js', + file: join(OUTPUT_DIR, 'bundle2.js'), format: 'cjs', exports: 'auto' } @@ -980,38 +991,38 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.deepStrictEqual(run('../_tmp/output/bundle1.js'), 42); - assert.deepStrictEqual(run('../_tmp/output/bundle2.js'), 43); - atomicWriteFileSync('test/_tmp/input/main2.js', 'export default 44'); + assert.deepStrictEqual(run(join(OUTPUT_DIR, 'bundle1.js')), 42); + assert.deepStrictEqual(run(join(OUTPUT_DIR, 'bundle2.js')), 43); + atomicWriteFileSync(join(INPUT_DIR, 'main2.js'), 'export default 44'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.deepStrictEqual(run('../_tmp/output/bundle1.js'), 42); - assert.deepStrictEqual(run('../_tmp/output/bundle2.js'), 44); + assert.deepStrictEqual(run(join(OUTPUT_DIR, 'bundle1.js')), 42); + assert.deepStrictEqual(run(join(OUTPUT_DIR, 'bundle2.js')), 44); } ]); }); it('allows watching only some configs', async () => { - await copy('test/watch/samples/multiple', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'multiple'), INPUT_DIR); await wait(100); watcher = rollup.watch([ { - input: 'test/_tmp/input/main1.js', + input: join(INPUT_DIR, 'main1.js'), watch: false, output: { - file: 'test/_tmp/output/bundle1.js', + file: join(OUTPUT_DIR, 'bundle1.js'), format: 'cjs', exports: 'auto' } }, { - input: 'test/_tmp/input/main2.js', + input: join(INPUT_DIR, 'main2.js'), output: { - file: 'test/_tmp/output/bundle2.js', + file: join(OUTPUT_DIR, 'bundle2.js'), format: 'cjs', exports: 'auto' } @@ -1023,19 +1034,19 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(existsSync(resolve(__dirname, '../_tmp/output/bundle1.js')), false); - assert.strictEqual(existsSync(resolve(__dirname, '../_tmp/output/bundle2.js')), true); - assert.deepStrictEqual(run('../_tmp/output/bundle2.js'), 43); + assert.strictEqual(existsSync(resolve(__dirname, join(OUTPUT_DIR, 'bundle1.js'))), false); + assert.strictEqual(existsSync(resolve(__dirname, join(OUTPUT_DIR, 'bundle2.js'))), true); + assert.deepStrictEqual(run(join(OUTPUT_DIR, 'bundle2.js')), 43); } ]); }); it('respects output.globals', async () => { - await copy('test/watch/samples/globals', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'globals'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'iife', globals: { jquery: 'jQuery' @@ -1049,7 +1060,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - const generated = readFileSync('test/_tmp/output/bundle.js', { + const generated = readFileSync(BUNDLE_FILE, { encoding: 'utf8' }); assert.ok(/jQuery/.test(generated)); @@ -1058,11 +1069,11 @@ describe('rollup.watch', () => { }); it('treats filenames literally, not as globs', async () => { - await copy('test/watch/samples/non-glob', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'non-glob'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -1073,15 +1084,15 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/[foo]/bar.js', `export const bar = 43;`); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(join(INPUT_DIR, '[foo]/bar.js'), `export const bar = 43;`); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); } ]); }); @@ -1090,11 +1101,11 @@ describe('rollup.watch', () => { let dynamicName; let staticName; let chunkName; - await copy('test/watch/samples/hashing', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'hashing'), INPUT_DIR); watcher = rollup.watch({ - input: ['test/_tmp/input/main-static.js', 'test/_tmp/input/main-dynamic.js'], + input: [join(INPUT_DIR, 'main-static.js'), join(INPUT_DIR, 'main-dynamic.js')], output: { - dir: 'test/_tmp/output', + dir: OUTPUT_DIR, format: 'cjs', exports: 'auto', entryFileNames: '[name].[hash].js', @@ -1107,15 +1118,15 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - [dynamicName, staticName, chunkName] = readdirSync('test/_tmp/output').sort(); - rmSync('test/_tmp/output', { + [dynamicName, staticName, chunkName] = readdirSync(OUTPUT_DIR).sort(); + rmSync(OUTPUT_DIR, { force: true, recursive: true }); // this should only update the hash of that particular entry point atomicWriteFileSync( - 'test/_tmp/input/main-static.js', + join(INPUT_DIR, 'main-static.js'), "import {value} from './shared';\nexport default 2 * value;" ); }, @@ -1124,9 +1135,8 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - const [newDynamicName, newStaticName, newChunkName] = - readdirSync('test/_tmp/output').sort(); - rmSync('test/_tmp/output', { + const [newDynamicName, newStaticName, newChunkName] = readdirSync(OUTPUT_DIR).sort(); + rmSync(OUTPUT_DIR, { force: true, recursive: true }); @@ -1136,15 +1146,14 @@ describe('rollup.watch', () => { staticName = newStaticName; // this should update all hashes - atomicWriteFileSync('test/_tmp/input/shared.js', 'export const value = 42;'); + atomicWriteFileSync(join(INPUT_DIR, 'shared.js'), 'export const value = 42;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - const [newDynamicName, newStaticName, newChunkName] = - readdirSync('test/_tmp/output').sort(); + const [newDynamicName, newStaticName, newChunkName] = readdirSync(OUTPUT_DIR).sort(); assert.notEqual(newStaticName, staticName); assert.notEqual(newDynamicName, dynamicName); assert.notEqual(newChunkName, chunkName); @@ -1154,11 +1163,11 @@ describe('rollup.watch', () => { it('runs transforms again on previously erroring files that were changed back', async () => { const brokenFiles = new Set(); - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); const INITIAL_CONTENT = 'export default 42;'; - atomicWriteFileSync('test/_tmp/input/main.js', INITIAL_CONTENT); + atomicWriteFileSync(ENTRY_FILE, INITIAL_CONTENT); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, plugins: { transform(code, id) { if (code.includes('broken')) { @@ -1174,7 +1183,7 @@ describe('rollup.watch', () => { } }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -1185,32 +1194,32 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default "broken";'); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, 'export default "broken";'); }, 'START', 'BUNDLE_START', 'ERROR:Broken in transform', () => { - atomicWriteFileSync('test/_tmp/input/main.js', INITIAL_CONTENT); + atomicWriteFileSync(ENTRY_FILE, INITIAL_CONTENT); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); } ]); }); it('skips filesystem writes when configured', async () => { let watchChangeCnt = 0; - await copy('test/watch/samples/skip-writes', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'skip-writes'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -1220,7 +1229,7 @@ describe('rollup.watch', () => { plugins: { watchChange(id) { watchChangeCnt++; - assert.strictEqual(id, resolve('test/_tmp/input/main.js')); + assert.strictEqual(id, ENTRY_FILE); } } }); @@ -1231,47 +1240,47 @@ describe('rollup.watch', () => { 'END', () => { watchChangeCnt = 0; - assert.strictEqual(existsSync('../_tmp/output/bundle.js'), false); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + assert.strictEqual(existsSync(BUNDLE_FILE), false); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(existsSync('../_tmp/output/bundle.js'), false); + assert.strictEqual(existsSync(BUNDLE_FILE), false); assert.strictEqual(watchChangeCnt, 1); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(existsSync('../_tmp/output/bundle.js'), false); + assert.strictEqual(existsSync(BUNDLE_FILE), false); assert.strictEqual(watchChangeCnt, 2); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', // 'END', event => { - assert.strictEqual(existsSync('../_tmp/output/bundle.js'), false); + assert.strictEqual(existsSync(BUNDLE_FILE), false); assert.strictEqual(watchChangeCnt, 3); // still aware of its output destination - assert.strictEqual(event.output[0], resolve('test/_tmp/output/bundle.js')); + assert.strictEqual(event.output[0], resolve(BUNDLE_FILE)); } ]); }); it('rebuilds immediately by default', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); await wait(300); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -1286,8 +1295,8 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); startTime = hrtime(); }, 'START', @@ -1295,7 +1304,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); const timeDiff = getTimeDiffInMs(startTime); assert.ok(timeDiff < 400, `Time difference ${timeDiff} < 400`); } @@ -1305,40 +1314,40 @@ describe('rollup.watch', () => { }).retries(1); it('observes configured build delays', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch( [ { - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } }, { - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, watch: { clearScreen: true }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } }, { - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, watch: { buildDelay: 1000 }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } }, { - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, watch: { buildDelay: 50 }, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' } @@ -1360,8 +1369,8 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - atomicWriteFileSync('test/_tmp/input/main.js', 'export default 43;'); + assert.strictEqual(run(BUNDLE_FILE), 42); + atomicWriteFileSync(ENTRY_FILE, 'export default 43;'); startTime = hrtime(); }, 'START', @@ -1375,7 +1384,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 43); + assert.strictEqual(run(BUNDLE_FILE), 43); const timeDiff = getTimeDiffInMs(startTime); assert.ok(timeDiff > 1000, `Time difference ${timeDiff} > 1000`); } @@ -1385,16 +1394,16 @@ describe('rollup.watch', () => { describe('addWatchFile', () => { it('supports adding additional watch files in plugin hooks', async () => { const watchChangeIds = new Set(); - const buildEndFile = resolve('test/_tmp/input/buildEnd'); - const buildStartFile = resolve('test/_tmp/input/buildStart'); - const generateBundleFile = resolve('test/_tmp/input/generateBUndle'); - const loadFile = resolve('test/_tmp/input/load'); - const moduleParsedFile = resolve('test/_tmp/input/moduleParsed'); - const renderChunkFile = resolve('test/_tmp/input/renderChunk'); - const renderStartFile = resolve('test/_tmp/input/renderStart'); - const resolveIdFile = resolve('test/_tmp/input/resolveId'); - const transformFile = resolve('test/_tmp/input/transform'); - const writeBundleFile = resolve('test/_tmp/input/writeBundle'); + const buildEndFile = resolve(join(INPUT_DIR, 'buildEnd')); + const buildStartFile = resolve(join(INPUT_DIR, 'buildStart')); + const generateBundleFile = resolve(join(INPUT_DIR, 'generateBUndle')); + const loadFile = resolve(join(INPUT_DIR, 'load')); + const moduleParsedFile = resolve(join(INPUT_DIR, 'moduleParsed')); + const renderChunkFile = resolve(join(INPUT_DIR, 'renderChunk')); + const renderStartFile = resolve(join(INPUT_DIR, 'renderStart')); + const resolveIdFile = resolve(join(INPUT_DIR, 'resolveId')); + const transformFile = resolve(join(INPUT_DIR, 'transform')); + const writeBundleFile = resolve(join(INPUT_DIR, 'writeBundle')); const watchFiles = [ buildEndFile, buildStartFile, @@ -1407,14 +1416,13 @@ describe('rollup.watch', () => { transformFile, writeBundleFile ]; - await copy('test/watch/samples/basic', 'test/_tmp/input'); - + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); await Promise.all(watchFiles.map(file => writeFile(file, 'initial'))); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -1460,7 +1468,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', async () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); // sometimes the watcher is triggered during the initial run watchChangeIds.clear(); @@ -1471,19 +1479,19 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.strictEqual(run(BUNDLE_FILE), 42); assert.deepStrictEqual([...watchChangeIds].sort(), watchFiles.sort()); } ]); }); it('respects changed watched files in the load hook', async () => { - const WATCHED_ID = resolve('test/_tmp/input/watched'); - await copy('test/watch/samples/watch-files', 'test/_tmp/input'); + const WATCHED_ID = join(INPUT_DIR, 'watched'); + await copy(join(SAMPLES_DIR, 'watch-files'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -1500,7 +1508,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 'initial'); + assert.strictEqual(run(BUNDLE_FILE), 'initial'); atomicWriteFileSync(WATCHED_ID, 'next'); }, 'START', @@ -1508,19 +1516,19 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 'next'); + assert.strictEqual(run(BUNDLE_FILE), 'next'); } ]); }); it('respects changed watched files in the transform hook and removes them if they are no longer watched', async () => { - const WATCHED_ID = resolve('test/_tmp/input/watched'); + const WATCHED_ID = join(INPUT_DIR, 'watched'); let addWatchFile = true; - await copy('test/watch/samples/watch-files', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'watch-files'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, @@ -1555,7 +1563,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 'initial'); + assert.strictEqual(run(BUNDLE_FILE), 'initial'); addWatchFile = false; atomicWriteFileSync(WATCHED_ID, 'next'); }, @@ -1564,7 +1572,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', async () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 'next'); + assert.strictEqual(run(BUNDLE_FILE), 'next'); atomicWriteFileSync(WATCHED_ID, 'other'); events.length = 0; await wait(400); @@ -1574,19 +1582,19 @@ describe('rollup.watch', () => { }); it('respects changed watched modules that are already part of the graph in the transform hook', async () => { - await copy('test/watch/samples/dependencies', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'dependencies'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, plugins: { transform(code, id) { if (id.endsWith('dep1.js')) { - this.addWatchFile(resolve('test/_tmp/input/dep2.js')); - const text = readFileSync('test/_tmp/input/dep2.js').toString().trim(); + this.addWatchFile(resolve(join(INPUT_DIR, 'dep2.js'))); + const text = readFileSync(join(INPUT_DIR, 'dep2.js')).toString().trim(); return `export default ${JSON.stringify(text)}`; } } @@ -1598,38 +1606,32 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual( - run('../_tmp/output/bundle.js'), - `dep1: "export default 'dep2';", dep2: "dep2"` - ); - atomicWriteFileSync('test/_tmp/input/dep2.js', 'export default "next";'); + assert.strictEqual(run(BUNDLE_FILE), `dep1: "export default 'dep2';", dep2: "dep2"`); + atomicWriteFileSync(join(INPUT_DIR, 'dep2.js'), 'export default "next";'); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual( - run('../_tmp/output/bundle.js'), - `dep1: "export default "next";", dep2: "next"` - ); + assert.strictEqual(run(BUNDLE_FILE), `dep1: "export default "next";", dep2: "next"`); } ]); }); it('respects changed watched directories in the transform hook', async () => { - const WATCHED_ID = resolve('test/_tmp/input/watched'); - await copy('test/watch/samples/watch-files', 'test/_tmp/input'); + const WATCHED_ID = join(INPUT_DIR, 'watched'); + await copy(join(SAMPLES_DIR, 'watch-files'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, plugins: { transform() { - this.addWatchFile('test/_tmp/input'); + this.addWatchFile(INPUT_DIR); return `export default ${existsSync(WATCHED_ID)}`; } } @@ -1640,7 +1642,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), true); + assert.strictEqual(run(BUNDLE_FILE), true); unlinkSync(WATCHED_ID); }, 'START', @@ -1648,25 +1650,25 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), false); + assert.strictEqual(run(BUNDLE_FILE), false); watcher.close(); } ]); }); it('respects initially missing added watched files', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, plugins: { transform() { - this.addWatchFile('test/_tmp/input/dep'); - return `export default ${existsSync('test/_tmp/input/dep')}`; + this.addWatchFile(join(INPUT_DIR, 'dep')); + return `export default ${existsSync(join(INPUT_DIR, 'dep'))}`; } } }); @@ -1676,33 +1678,33 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), false); - atomicWriteFileSync('test/_tmp/input/dep', ''); + assert.strictEqual(run(BUNDLE_FILE), false); + atomicWriteFileSync(join(INPUT_DIR, 'dep'), ''); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), true); + assert.strictEqual(run(BUNDLE_FILE), true); } ]); }); it('respects unlinked and re-added watched files', async () => { - await copy('test/watch/samples/basic', 'test/_tmp/input'); - await writeFile('test/_tmp/input/dep', ''); + await copy(join(SAMPLES_DIR, 'basic'), INPUT_DIR); + await writeFile(join(INPUT_DIR, 'dep'), ''); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, plugins: { transform() { - this.addWatchFile('test/_tmp/input/dep'); - return `export default ${existsSync('test/_tmp/input/dep')}`; + this.addWatchFile(join(INPUT_DIR, 'dep')); + return `export default ${existsSync(join(INPUT_DIR, 'dep'))}`; } } }); @@ -1712,43 +1714,43 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), true); - unlinkSync('test/_tmp/input/dep'); + assert.strictEqual(run(BUNDLE_FILE), true); + unlinkSync(join(INPUT_DIR, 'dep')); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), false); - atomicWriteFileSync('test/_tmp/input/dep', ''); + assert.strictEqual(run(BUNDLE_FILE), false); + atomicWriteFileSync(join(INPUT_DIR, 'dep'), ''); }, 'START', 'BUNDLE_START', 'BUNDLE_END', 'END', () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), true); + assert.strictEqual(run(BUNDLE_FILE), true); } ]); }); it('does not rerun the transform hook if a non-watched change triggered the re-run', async () => { - const WATCHED_ID = resolve('test/_tmp/input/watched'); + const WATCHED_ID = join(INPUT_DIR, 'watched'); let transformRuns = 0; - await copy('test/watch/samples/watch-files', 'test/_tmp/input'); + await copy(join(SAMPLES_DIR, 'watch-files'), INPUT_DIR); await wait(100); - await writeFile('test/_tmp/input/alsoWatched', 'initial'); + await writeFile(join(INPUT_DIR, 'alsoWatched'), 'initial'); watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', + input: ENTRY_FILE, output: { - file: 'test/_tmp/output/bundle.js', + file: BUNDLE_FILE, format: 'cjs', exports: 'auto' }, plugins: { buildStart() { - this.addWatchFile('test/_tmp/input/alsoWatched'); + this.addWatchFile(join(INPUT_DIR, 'alsoWatched')); }, transform() { transformRuns++; @@ -1764,7 +1766,7 @@ describe('rollup.watch', () => { 'END', () => { assert.strictEqual(transformRuns, 1); - atomicWriteFileSync('test/_tmp/input/alsoWatched', 'next'); + atomicWriteFileSync(join(INPUT_DIR, 'alsoWatched'), 'next'); }, 'START', 'BUNDLE_START', @@ -1786,6 +1788,10 @@ function run(file) { function sequence(watcher, events, timeout = 300) { const handledEvents = []; + const allEvents = []; + const formatEvents = () => + `\nHandled events:\n${handledEvents.join('\n')}\n\nWatcher events:\n${allEvents.join('\n')}`; + watcher.on('event', event => allEvents.push(JSON.stringify(event))); const sequencePromise = new Promise((fulfil, reject) => { function go(event) { const next = events.shift(); @@ -1795,26 +1801,36 @@ function sequence(watcher, events, timeout = 300) { fulfil(); } else if (typeof next === 'string') { handledEvents.push(next); - const [eventCode, eventMessage] = next.split(':'); + const [eventCode, ...eventMessageParts] = next.split(':'); + const eventMessage = eventMessageParts.join(':'); watcher.once('event', event => { if (event.code !== eventCode) { watcher.close(); if (event.code === 'ERROR') console.log(event.error); - reject(new Error(`Expected ${eventCode} event, got ${event.code}`)); + reject(new Error(`Expected ${eventCode} event, got ${event.code}.${formatEvents()}`)); } else if ( eventCode === 'ERROR' && eventMessage && event.error.message !== eventMessage ) { reject( - new Error(`Expected to throw "${eventMessage}" but got "${event.error.message}".`) + new Error( + `Expected to throw "${eventMessage}" but got "${event.error.message}".${formatEvents()}` + ) ); } else { go(event); } }); } else { - wait(timeout) // gah, this appears to be necessary to fix random errors + // "next" is a function + // This solves two problems: + // - Sometimes a change in the function does not trigger a rebuild if + // it happens too quickly, i.e. shorter than 300ms after the previous + // change. + // - On the flipside, sometimes a single change triggers two builds. + // In that case, waiting here "swallows" the second build. + wait(timeout) .then(() => { handledEvents.push(`fn: ${JSON.stringify(event)}`); next(event); @@ -1822,6 +1838,7 @@ function sequence(watcher, events, timeout = 300) { }) .catch(error => { watcher.close(); + error.message += formatEvents(); reject(error); }); } @@ -1831,7 +1848,7 @@ function sequence(watcher, events, timeout = 300) { }); return withTimeout(sequencePromise, 20_000, () => { - throw new Error(`Test timed out\n${handledEvents.join('\n')}`); + throw new Error(`Test timed out.\nHandled events:\n${handledEvents.join('\n')}`); }).then(() => wait(100)); }