Skip to content

Commit 137ed22

Browse files
committed
test(typescript): fix tests related to rollup's new logging
See rollup/rollup#5424
1 parent b13763d commit 137ed22

5 files changed

Lines changed: 73 additions & 21 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Snapshot report for `test/test.js`
2+
3+
The actual snapshot is saved in `test.js.snap`.
4+
5+
Generated by [AVA](https://avajs.dev).
6+
7+
## warns for invalid module types
8+
9+
> Snapshot 1
10+
11+
[
12+
{
13+
code: 'PLUGIN_WARNING',
14+
message: '[plugin typescript] @rollup/plugin-typescript TS6046: Argument for \'--module\' option must be: \'none\', \'commonjs\', \'amd\', \'system\', \'umd\', \'es6\', \'es2015\', \'es2020\', \'es2022\', \'esnext\', \'node16\', \'node18\', \'node20\', \'nodenext\', \'preserve\'.',
15+
plugin: 'typescript',
16+
pluginCode: 'TS6046',
17+
[Symbol(augmented)]: true,
18+
},
19+
]
20+
21+
## should throw on bad options
22+
23+
> Snapshot 1
24+
25+
[
26+
{
27+
code: 'PLUGIN_WARNING',
28+
message: '[plugin typescript] @rollup/plugin-typescript TS5023: Unknown compiler option \'foo\'.',
29+
plugin: 'typescript',
30+
pluginCode: 'TS5023',
31+
[Symbol(augmented)]: true,
32+
},
33+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should throw on bad options 1`] = `
4+
[
5+
{
6+
"code": "PLUGIN_WARNING",
7+
"message": "[plugin typescript] @rollup/plugin-typescript TS5023: Unknown compiler option 'foo'.",
8+
"plugin": "typescript",
9+
"pluginCode": "TS5023",
10+
Symbol(augmented): true,
11+
},
12+
]
13+
`;
14+
15+
exports[`warns for invalid module types 1`] = `
16+
[
17+
{
18+
"code": "PLUGIN_WARNING",
19+
"message": "[plugin typescript] @rollup/plugin-typescript TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'node18', 'node20', 'nodenext', 'preserve'.",
20+
"plugin": "typescript",
21+
"pluginCode": "TS6046",
22+
Symbol(augmented): true,
23+
},
24+
]
25+
`;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`fails without tslib installed 1`] = `[RollupError: @rollup/plugin-typescript: Could not find module 'tslib', which is required by this plugin. Is it installed?]`;
3+
exports[`fails without tslib installed 1`] = `[RollupError: [plugin typescript] @rollup/plugin-typescript: Could not find module 'tslib', which is required by this plugin. Is it installed?]`;

packages/typescript/test/snapshots/warnings.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ exports[`bad module in tsconfig 1`] = `
44
[
55
{
66
"code": "PLUGIN_WARNING",
7-
"message": "@rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.",
7+
"message": "[plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.",
88
"plugin": "typescript",
9+
Symbol(augmented): true,
910
},
1011
]
1112
`;

packages/typescript/test/test.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,8 @@ test.sequential('warns for invalid module types', async () => {
375375
}
376376
})
377377
);
378-
expect(warnings).toEqual([
379-
{
380-
code: 'PLUGIN_WARNING',
381-
plugin: 'typescript',
382-
pluginCode: 'TS6046',
383-
message: `@rollup/plugin-typescript TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'node18', 'node20', 'nodenext', 'preserve'.`
384-
}
385-
]);
378+
379+
expect(warnings).toMatchSnapshot();
386380
});
387381
test.sequential('ignores case of module types', async () => {
388382
await expectNoError(
@@ -472,7 +466,10 @@ test.sequential('reports diagnostics and throws if errors occur during transpila
472466
onwarn
473467
})
474468
);
475-
expect(caughtError.message).toBe('@rollup/plugin-typescript TS1110: Type expected.');
469+
470+
expect(caughtError.message).toBe(
471+
'[plugin typescript] fixtures/syntax-error/missing-type.ts (1:8): @rollup/plugin-typescript TS1110: Type expected.'
472+
);
476473
expect(caughtError.pluginCode).toBe('TS1110');
477474
});
478475
test.sequential('ignore type errors if noEmitOnError is false', async () => {
@@ -494,7 +491,9 @@ test.sequential('ignore type errors if noEmitOnError is false', async () => {
494491
expect(warnings[0].code).toBe('PLUGIN_WARNING');
495492
expect(warnings[0].plugin).toBe('typescript');
496493
expect(warnings[0].pluginCode).toBe('TS1110');
497-
expect(warnings[0].message).toBe('@rollup/plugin-typescript TS1110: Type expected.');
494+
expect(warnings[0].message).toBe(
495+
'[plugin typescript] fixtures/syntax-error/missing-type.ts (1:8): @rollup/plugin-typescript TS1110: Type expected.'
496+
);
498497
expect(warnings[0].loc.line).toBe(1);
499498
expect(warnings[0].loc.column).toBe(8);
500499
expect(warnings[0].loc.file.includes('missing-type.ts')).toBe(true);
@@ -712,17 +711,11 @@ test.sequential('should throw on bad options', async () => {
712711
}
713712
}),
714713
{
715-
message: "@rollup/plugin-typescript: Couldn't process compiler options"
714+
message: "[plugin typescript] @rollup/plugin-typescript: Couldn't process compiler options"
716715
}
717716
);
718-
expect(warnings).toEqual([
719-
{
720-
code: 'PLUGIN_WARNING',
721-
plugin: 'typescript',
722-
pluginCode: 'TS5023',
723-
message: `@rollup/plugin-typescript TS5023: Unknown compiler option 'foo'.`
724-
}
725-
]);
717+
718+
expect(warnings).toMatchSnapshot();
726719
});
727720
test.sequential('should handle re-exporting types', async () => {
728721
const bundle = await rollup({

0 commit comments

Comments
 (0)