Skip to content

Commit

Permalink
tests: add use this plugin as ci checker test
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed Mar 30, 2024
1 parent eefa2d0 commit da618a8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export default createUnplugin<Options | undefined>((options) => {
consola.info(
`You can just copy following all duplicated dependencies as the value of ${c.magenta('ignore')} option:`,
);
console.log(`\n${highlight(JSON.stringify(duplicatedDeps, null, 4))}\n`);
console.error(`\n${highlight(JSON.stringify(duplicatedDeps, null, 4))}\n`);
}

// eslint-disable-next-line unicorn/no-process-exit
Expand Down
43 changes: 43 additions & 0 deletions tests/fixtures/mono/app/ci-check-error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[error] packages @pixi/constants, @pixi/settings, @pixi/utils, @yutengjing/foo, axios is bundled multiple times, fix them can reduce the bundle size by 52.386kb

@pixi/constants(10.934kb):
- 7.0.0(5.467kb) imported by @pixi/[email protected], @pixi/[email protected]
- 7.2.4(5.467kb) imported by @pixi/[email protected]

@pixi/settings(10.884kb):
- 7.0.0(8.134kb) imported by @pixi/[email protected]
- 7.2.4(2.750kb) imported by @pixi/[email protected]

@pixi/utils(82.901kb):
- 7.0.0(38.550kb) imported by tests/fixtures/mono/packages/pkg2/index.js
- 7.2.4(44.351kb) imported by tests/fixtures/mono/packages/pkg1/index.js

@yutengjing/foo(0.470kb):
- 1.0.3(0.235kb)
- node_modules/.pnpm/@[email protected][email protected]/node_modules/@yutengjing/foo imported by tests/fixtures/mono/packages/pkg1/index.js
- node_modules/.pnpm/@[email protected][email protected]/node_modules/@yutengjing/foo imported by tests/fixtures/mono/packages/pkg2/index.js

axios(30.218kb):
- 1.4.0(30.218kb) imported by tests/fixtures/mono/packages/pkg1/index.js

{
"@pixi/constants": [
"7.0.0",
"7.2.4"
],
"@pixi/settings": [
"7.0.0",
"7.2.4"
],
"@pixi/utils": [
"7.0.0",
"7.2.4"
],
"@yutengjing/foo": [
"1.0.3"
],
"axios": [
"0.27.2",
"1.4.0"
]
}
28 changes: 14 additions & 14 deletions tests/fixtures/mono/app/stderr-webpack.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[warn] packages @pixi/constants, @pixi/settings, @pixi/utils, @yutengjing/foo, axios is bundled multiple times, fix them can reduce the bundle size by 72.044kb

@pixi/constants(10.934kb}):
- 7.0.0(5.467kb}) imported by @pixi/[email protected], @pixi/[email protected]
- 7.2.4(5.467kb}) imported by @pixi/[email protected]
@pixi/constants(10.934kb):
- 7.0.0(5.467kb) imported by @pixi/[email protected], @pixi/[email protected]
- 7.2.4(5.467kb) imported by @pixi/[email protected]

@pixi/settings(10.884kb}):
- 7.0.0(8.134kb}) imported by @pixi/[email protected]
- 7.2.4(2.750kb}) imported by @pixi/[email protected]
@pixi/settings(10.884kb):
- 7.0.0(8.134kb) imported by @pixi/[email protected]
- 7.2.4(2.750kb) imported by @pixi/[email protected]

@pixi/utils(82.901kb}):
- 7.0.0(38.550kb}) imported by tests/fixtures/mono/packages/pkg2/index.js
- 7.2.4(44.351kb}) imported by tests/fixtures/mono/packages/pkg1/index.js
@pixi/utils(82.901kb):
- 7.0.0(38.550kb) imported by tests/fixtures/mono/packages/pkg2/index.js
- 7.2.4(44.351kb) imported by tests/fixtures/mono/packages/pkg1/index.js

@yutengjing/foo(0.470kb}):
- 1.0.3(0.235kb})
@yutengjing/foo(0.470kb):
- 1.0.3(0.235kb)
- node_modules/.pnpm/@[email protected][email protected]/node_modules/@yutengjing/foo imported by tests/fixtures/mono/packages/pkg1/index.js
- node_modules/.pnpm/@[email protected][email protected]/node_modules/@yutengjing/foo imported by tests/fixtures/mono/packages/pkg2/index.js

axios(49.876kb}):
- 0.27.2(19.658kb}) imported by tests/fixtures/mono/packages/pkg2/index.js
- 1.4.0 (30.218kb}) imported by tests/fixtures/mono/packages/pkg1/index.js
axios(49.876kb):
- 0.27.2(19.658kb) imported by tests/fixtures/mono/packages/pkg2/index.js
- 1.4.0 (30.218kb) imported by tests/fixtures/mono/packages/pkg1/index.js
16 changes: 8 additions & 8 deletions tests/fixtures/mono/app/stderr.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[warn] packages @pixi/utils, @yutengjing/foo, axios is bundled multiple times, fix them can reduce the bundle size by 58.443kb

@pixi/utils(82.901kb}):
- 7.0.0(38.550kb}) imported by tests/fixtures/mono/packages/pkg2/index.js
- 7.2.4(44.351kb}) imported by tests/fixtures/mono/packages/pkg1/index.js
@pixi/utils(82.901kb):
- 7.0.0(38.550kb) imported by tests/fixtures/mono/packages/pkg2/index.js
- 7.2.4(44.351kb) imported by tests/fixtures/mono/packages/pkg1/index.js

@yutengjing/foo(0.470kb}):
- 1.0.3(0.235kb})
@yutengjing/foo(0.470kb):
- 1.0.3(0.235kb)
- node_modules/.pnpm/@[email protected][email protected]/node_modules/@yutengjing/foo imported by tests/fixtures/mono/packages/pkg1/index.js
- node_modules/.pnpm/@[email protected][email protected]/node_modules/@yutengjing/foo imported by tests/fixtures/mono/packages/pkg2/index.js

axios(49.876kb}):
- 0.27.2(19.658kb}) imported by tests/fixtures/mono/packages/pkg2/index.js
- 1.4.0 (30.218kb}) imported by tests/fixtures/mono/packages/pkg1/index.js
axios(49.876kb):
- 0.27.2(19.658kb) imported by tests/fixtures/mono/packages/pkg2/index.js
- 1.4.0 (30.218kb) imported by tests/fixtures/mono/packages/pkg1/index.js
8 changes: 8 additions & 0 deletions tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const exec = async (command: string) => {
const result = await execa(cmd, args, {
cwd: testCwd,
preferLocal: true,
reject: false,
env: {
NO_COLOR: 'true',
},
Expand Down Expand Up @@ -60,3 +61,10 @@ test('no pkg size', async () => {
// await fs.writeFile(stderrPath, result.stderr, 'utf8');
expect(result.stderr).toBe(await fs.readFile(stderrPath, 'utf8'));
});

test('use in ci check', async () => {
const result = await exec('vite build -c vite.config.throw-error.mts');
const stderrPath = resolve(testCwd, 'ci-check-error.txt');
await fs.writeFile(stderrPath, result.stderr, 'utf8');
expect(result.stderr).toBe(await fs.readFile(stderrPath, 'utf8'));
});

0 comments on commit da618a8

Please sign in to comment.