Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix broken Windows CLI tests #3249

Merged
merged 11 commits into from Nov 22, 2019
339 changes: 145 additions & 194 deletions cli/run/batchWarnings.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/run/build.ts
Expand Up @@ -81,8 +81,8 @@ export default function build(
}
}
})
.catch((err: any) => {
if (warnings.count > 0) warnings.flush();
.catch((err: Error) => {
warnings.flush();
handleError(err);
});
}
1 change: 1 addition & 0 deletions src/Graph.ts
Expand Up @@ -395,6 +395,7 @@ export default class Graph {
for (const cyclePath of cyclePaths) {
this.warn({
code: 'CIRCULAR_DEPENDENCY',
cycle: cyclePath,
importer: cyclePath[0],
message: `Circular dependency: ${cyclePath.join(' -> ')}`
});
Expand Down
5 changes: 3 additions & 2 deletions src/rollup/types.d.ts
Expand Up @@ -11,6 +11,7 @@ export interface RollupError extends RollupLogProps {

export interface RollupWarning extends RollupLogProps {
chunkName?: string;
cycle?: string[];
exporter?: string;
exportName?: string;
guess?: string;
Expand Down Expand Up @@ -500,10 +501,10 @@ export interface OutputOptions {
}

export type WarningHandlerWithDefault = (
warning: string | RollupWarning,
warning: RollupWarning,
defaultHandler: WarningHandler
) => void;
export type WarningHandler = (warning: string | RollupWarning) => void;
export type WarningHandler = (warning: RollupWarning) => void;

export interface SerializedTimings {
[label: string]: [number, number, number];
Expand Down
7 changes: 4 additions & 3 deletions src/utils/collapseSourcemaps.ts
Expand Up @@ -154,9 +154,10 @@ function getLinkMap(graph: Graph) {

graph.warn({
code: 'SOURCEMAP_BROKEN',
message: `Sourcemap is likely to be incorrect: a plugin${
map.plugin ? ` ('${map.plugin}')` : ``
} was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
message:
`Sourcemap is likely to be incorrect: a plugin (${map.plugin}) was used to transform ` +
"files, but didn't generate a sourcemap for the transformation. Consult the plugin " +
'documentation for help',
plugin: map.plugin,
url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect`
});
Expand Down
12 changes: 0 additions & 12 deletions test/cli/samples/custom-frame-log-stack/_config.js

This file was deleted.

1 change: 0 additions & 1 deletion test/cli/samples/custom-frame-log-stack/main.js

This file was deleted.

15 changes: 0 additions & 15 deletions test/cli/samples/custom-frame-log-stack/rollup.config.js

This file was deleted.

13 changes: 9 additions & 4 deletions test/cli/samples/custom-frame-with-pos/_config.js
@@ -1,10 +1,15 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'custom (plugin generated) code frame taking priority over pos generated one',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(/custom code frame/.test(stderr));
}
stderr: stderr =>
assertStderrIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js (1:5)\n' +
'custom code frame\n' +
'Error: My error.'
)
};
12 changes: 9 additions & 3 deletions test/cli/samples/custom-frame/_config.js
@@ -1,10 +1,16 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'errors with custom (plugin generated) code frame',
description: 'errors with plugin generated code frames also contain stack',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(/custom code frame/.test(stderr));
assertStderrIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js\ncustom code frame\nError: My error.\n' +
' at Object.transform'
);
assertStderrIncludes(stderr, 'rollup.config.js:11:17');
}
};
6 changes: 2 additions & 4 deletions test/cli/samples/empty-chunk-multiple/_config.js
@@ -1,10 +1,8 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'shows warning when multiple chunks empty',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(stderr.includes('(!) Generated empty chunks\na, b'));
}
stderr: stderr => assertStderrIncludes(stderr, '(!) Generated empty chunks\na, b')
};
6 changes: 2 additions & 4 deletions test/cli/samples/empty-chunk/_config.js
@@ -1,10 +1,8 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'shows warning when chunk empty',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(stderr.includes('(!) Generated an empty chunk\nmain'));
}
stderr: stderr => assertStderrIncludes(stderr, '(!) Generated an empty chunk\nmain')
};
18 changes: 18 additions & 0 deletions test/cli/samples/warn-broken-sourcemap/_config.js
@@ -0,0 +1,18 @@
const fs = require('fs');
const path = require('path');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'displays warnings for broken sourcemaps',
command: 'rollup -c',
stderr: stderr => {
fs.unlinkSync(path.resolve(__dirname, 'bundle'));
fs.unlinkSync(path.resolve(__dirname, 'bundle.map'));
assertStderrIncludes(
stderr,
'(!) Broken sourcemap\n' +
'https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect\n' +
"Plugins that transform code (such as 'test-plugin1', 'test-plugin2' and 'test-plugin3') should generate accompanying sourcemaps"
);
}
};
1 change: 1 addition & 0 deletions test/cli/samples/warn-broken-sourcemap/main.js
@@ -0,0 +1 @@
console.log('main');
28 changes: 28 additions & 0 deletions test/cli/samples/warn-broken-sourcemap/rollup.config.js
@@ -0,0 +1,28 @@
module.exports = {
input: 'main.js',
plugins: [
{
name: 'test-plugin1',
transform(code) {
return code + '/*1*/';
}
},
{
name: 'test-plugin2',
transform(code) {
return code + '/*2*/';
}
},
{
name: 'test-plugin3',
transform(code) {
return code + '/*3*/';
}
}
],
output: {
format: 'esm',
file: 'bundle',
sourcemap: true
}
};
16 changes: 16 additions & 0 deletions test/cli/samples/warn-circular-multiple/_config.js
@@ -0,0 +1,16 @@
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'warns for multiple circular dependencies',
command: 'rollup -c',
stderr: stderr =>
assertStderrIncludes(
stderr,
'(!) Circular dependencies\n' +
'main.js -> dep1.js -> main.js\n' +
'main.js -> dep2.js -> main.js\n' +
'main.js -> dep3.js -> main.js\n' +
'...and 3 more\n' +
''
)
};
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular-multiple/dep1.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep1');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular-multiple/dep2.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep2');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular-multiple/dep3.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep3');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular-multiple/dep4.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep5');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular-multiple/dep5.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep5');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular-multiple/dep6.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep6');
7 changes: 7 additions & 0 deletions test/cli/samples/warn-circular-multiple/main.js
@@ -0,0 +1,7 @@
import './dep1.js';
import './dep2.js';
import './dep3.js';
import './dep4.js';
import './dep5.js';
import './dep6.js';
console.log('main');
6 changes: 6 additions & 0 deletions test/cli/samples/warn-circular-multiple/rollup.config.js
@@ -0,0 +1,6 @@
module.exports = {
input: 'main.js',
output: {
format: 'esm'
}
};
8 changes: 8 additions & 0 deletions test/cli/samples/warn-circular/_config.js
@@ -0,0 +1,8 @@
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'warns for circular dependencies',
command: 'rollup -c',
stderr: stderr =>
assertStderrIncludes(stderr, '(!) Circular dependency\n' + 'main.js -> dep.js -> main.js\n')
};
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular/dep.js
@@ -0,0 +1,2 @@
import './main.js';
console.log('dep');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-circular/main.js
@@ -0,0 +1,2 @@
import './dep.js';
console.log('main');
6 changes: 6 additions & 0 deletions test/cli/samples/warn-circular/rollup.config.js
@@ -0,0 +1,6 @@
module.exports = {
input: 'main.js',
output: {
format: 'esm'
}
};
28 changes: 28 additions & 0 deletions test/cli/samples/warn-eval-multiple/_config.js
@@ -0,0 +1,28 @@
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'warns when eval is used multiple times',
command: 'rollup -c',
stderr: stderr =>
assertStderrIncludes(
stderr,
'(!) Use of eval is strongly discouraged\n' +
'https://rollupjs.org/guide/en/#avoiding-eval\n' +
'dep1.js\n' +
'1: eval(\'console.log("Hello");\');\n' +
' ^\n' +
'dep2.js\n' +
'1: eval(\'console.log("Hello");\');\n' +
' ^\n' +
'2: eval(\'console.log("Hello again");\');\n' +
'...and 1 other occurrence\n' +
'dep3.js\n' +
'1: eval(\'console.log("Hello");\');\n' +
' ^\n' +
'2: eval(\'console.log("Hello again");\');\n' +
'3: eval(\'console.log("Hello again and again");\');\n' +
'...and 2 other occurrences\n' +
'\n' +
'...and 3 other files'
)
};
1 change: 1 addition & 0 deletions test/cli/samples/warn-eval-multiple/dep1.js
@@ -0,0 +1 @@
eval('console.log("Hello");');
2 changes: 2 additions & 0 deletions test/cli/samples/warn-eval-multiple/dep2.js
@@ -0,0 +1,2 @@
eval('console.log("Hello");');
eval('console.log("Hello again");');
3 changes: 3 additions & 0 deletions test/cli/samples/warn-eval-multiple/dep3.js
@@ -0,0 +1,3 @@
eval('console.log("Hello");');
eval('console.log("Hello again");');
eval('console.log("Hello again and again");');
1 change: 1 addition & 0 deletions test/cli/samples/warn-eval-multiple/dep4.js
@@ -0,0 +1 @@
eval('console.log("Hello");');
1 change: 1 addition & 0 deletions test/cli/samples/warn-eval-multiple/dep5.js
@@ -0,0 +1 @@
eval('console.log("Hello");');
7 changes: 7 additions & 0 deletions test/cli/samples/warn-eval-multiple/main.js
@@ -0,0 +1,7 @@
import './dep1.js';
import './dep2.js';
import './dep3.js';
import './dep4.js';
import './dep5.js';

eval('foo');
6 changes: 6 additions & 0 deletions test/cli/samples/warn-eval-multiple/rollup.config.js
@@ -0,0 +1,6 @@
module.exports = {
input: 'main.js',
output: {
format: 'esm'
}
};
15 changes: 15 additions & 0 deletions test/cli/samples/warn-eval/_config.js
@@ -0,0 +1,15 @@
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'warns when eval is used',
command: 'rollup -c',
stderr: stderr =>
assertStderrIncludes(
stderr,
'(!) Use of eval is strongly discouraged\n' +
'https://rollupjs.org/guide/en/#avoiding-eval\n' +
'main.js\n' +
"1: eval('foo');\n" +
' ^'
)
};
1 change: 1 addition & 0 deletions test/cli/samples/warn-eval/main.js
@@ -0,0 +1 @@
eval('foo');
6 changes: 6 additions & 0 deletions test/cli/samples/warn-eval/rollup.config.js
@@ -0,0 +1,6 @@
module.exports = {
input: 'main.js',
output: {
format: 'esm'
}
};