Skip to content

Commit becd728

Browse files
authored
feat: Add integration tests for older bundler versions (#44)
Adding in older versions of bundlers as well as the integration tests for them.
1 parent cfb84b4 commit becd728

File tree

19 files changed

+818
-372
lines changed

19 files changed

+818
-372
lines changed

.changeset/breezy-horses-rule.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@codecov/webpack-plugin": patch
3+
"@codecov/bundler-plugin-core": patch
4+
"@codecov/rollup-plugin": patch
5+
"@codecov/vite-plugin": patch
6+
---
7+
8+
Add duration to webpack bundler plugin directly

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ jobs:
202202
fail-fast: false
203203
matrix:
204204
node-version: [
205-
"18.19.0",
206-
"20.10.0"
205+
"18.x",
206+
"20.x"
207207
]
208208
steps:
209209
- name: Checkout

examples/webpack/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
codecovWebpackPlugin({
1313
enableBundleAnalysis: true,
1414
dryRun: true,
15+
bundleName: "webpack-example",
1516
}),
1617
],
1718
};

integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Generating rollup stats version 3 matches the snapshot 1`] = `
4+
{
5+
"assets": [
6+
{
7+
"name": "main-3e7d1fad.js",
8+
"normalized": "main-*.js",
9+
"size": 544589,
10+
},
11+
],
12+
"builtAt": Any<Number>,
13+
"bundleName": "rollup-test-es",
14+
"bundler": {
15+
"name": "rollup",
16+
"version": "3.29.4",
17+
},
18+
"chunks": [
19+
{
20+
"entry": true,
21+
"files": [
22+
"main-3e7d1fad.js",
23+
],
24+
"id": "main",
25+
"initial": false,
26+
"names": [
27+
"main",
28+
],
29+
"uniqueId": "0-main",
30+
},
31+
],
32+
"duration": Any<Number>,
33+
"modules": [
34+
{
35+
"chunkUniqueIds": [
36+
"0-main",
37+
],
38+
"name": "./commonjsHelpers.js",
39+
"size": 315,
40+
},
41+
{
42+
"chunkUniqueIds": [
43+
"0-main",
44+
],
45+
"name": "../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js",
46+
"size": 544001,
47+
},
48+
{
49+
"chunkUniqueIds": [
50+
"0-main",
51+
],
52+
"name": "./test-apps/rollup/src/getRandomNumber.js",
53+
"size": 98,
54+
},
55+
{
56+
"chunkUniqueIds": [
57+
"0-main",
58+
],
59+
"name": "./test-apps/rollup/src/main.js",
60+
"size": 168,
61+
},
62+
],
63+
"plugin": {
64+
"name": "codecov-rollup-bundle-analysis-plugin",
65+
"version": "1.0.0",
66+
},
67+
"version": "1",
68+
}
69+
`;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Generating rollup stats version 4 matches the snapshot 1`] = `
4+
{
5+
"assets": [
6+
{
7+
"name": "main--erNqm0D.js",
8+
"normalized": "main--erNqm0D.js",
9+
"size": 544589,
10+
},
11+
],
12+
"builtAt": Any<Number>,
13+
"bundleName": "rollup-test-es",
14+
"bundler": {
15+
"name": "rollup",
16+
"version": "4.6.0",
17+
},
18+
"chunks": [
19+
{
20+
"entry": true,
21+
"files": [
22+
"main--erNqm0D.js",
23+
],
24+
"id": "main",
25+
"initial": false,
26+
"names": [
27+
"main",
28+
],
29+
"uniqueId": "0-main",
30+
},
31+
],
32+
"duration": Any<Number>,
33+
"modules": [
34+
{
35+
"chunkUniqueIds": [
36+
"0-main",
37+
],
38+
"name": "./commonjsHelpers.js",
39+
"size": 315,
40+
},
41+
{
42+
"chunkUniqueIds": [
43+
"0-main",
44+
],
45+
"name": "../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js",
46+
"size": 544001,
47+
},
48+
{
49+
"chunkUniqueIds": [
50+
"0-main",
51+
],
52+
"name": "./test-apps/rollup/src/getRandomNumber.js",
53+
"size": 98,
54+
},
55+
{
56+
"chunkUniqueIds": [
57+
"0-main",
58+
],
59+
"name": "./test-apps/rollup/src/main.js",
60+
"size": 168,
61+
},
62+
],
63+
"plugin": {
64+
"name": "codecov-rollup-bundle-analysis-plugin",
65+
"version": "1.0.0",
66+
},
67+
"version": "1",
68+
}
69+
`;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
2+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
3+
import path from "path";
4+
import fs from "fs";
5+
import { type Output } from "@codecov/bundler-plugin-core";
6+
import { rollup as rollupV3 } from "rollupV3";
7+
// @ts-expect-error - no types
8+
import resolve from "@rollup/plugin-node-resolve";
9+
import commonjs from "@rollup/plugin-commonjs";
10+
import { codecovRollupPlugin } from "@codecov/rollup-plugin";
11+
12+
describe("Generating rollup stats", () => {
13+
describe("version 3", () => {
14+
let stats: Output;
15+
const rollupPath = path.resolve(__dirname, "../../../test-apps/rollup");
16+
beforeAll(async () => {
17+
await rollupV3({
18+
input: `${rollupPath}/src/main.js`,
19+
plugins: [
20+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
21+
resolve(),
22+
commonjs(),
23+
codecovRollupPlugin({
24+
enableBundleAnalysis: true,
25+
dryRun: true,
26+
bundleName: "rollup-test",
27+
}),
28+
],
29+
}).then((bundle) =>
30+
bundle.write({
31+
dir: `${rollupPath}/distV3`,
32+
entryFileNames: "[name]-[hash].js",
33+
}),
34+
);
35+
});
36+
37+
afterAll(() => {
38+
fs.rm(
39+
path.resolve(rollupPath, "distV3"),
40+
{ recursive: true, force: true },
41+
() => null,
42+
);
43+
});
44+
45+
it("matches the snapshot", () => {
46+
const statsFilePath = path.resolve(
47+
rollupPath,
48+
"distV3/codecov-bundle-stats.json",
49+
);
50+
51+
const statsData = fs.readFileSync(statsFilePath);
52+
stats = JSON.parse(statsData.toString()) as Output;
53+
54+
expect(stats).toMatchSnapshot({
55+
builtAt: expect.any(Number),
56+
duration: expect.any(Number),
57+
});
58+
});
59+
});
60+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
2+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
3+
import path from "path";
4+
import fs from "fs";
5+
import { type Output } from "@codecov/bundler-plugin-core";
6+
import { rollup as rollupV4 } from "rollupV4";
7+
// @ts-expect-error - no types
8+
import resolve from "@rollup/plugin-node-resolve";
9+
import commonjs from "@rollup/plugin-commonjs";
10+
import { codecovRollupPlugin } from "@codecov/rollup-plugin";
11+
12+
describe("Generating rollup stats", () => {
13+
describe("version 4", () => {
14+
let stats: Output;
15+
const rollupPath = path.resolve(__dirname, "../../../test-apps/rollup");
16+
beforeAll(async () => {
17+
await rollupV4({
18+
input: `${rollupPath}/src/main.js`,
19+
plugins: [
20+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
21+
resolve(),
22+
commonjs(),
23+
codecovRollupPlugin({
24+
enableBundleAnalysis: true,
25+
dryRun: true,
26+
bundleName: "rollup-test",
27+
}),
28+
],
29+
}).then((bundle) =>
30+
bundle.write({
31+
dir: `${rollupPath}/distV4`,
32+
entryFileNames: "[name]-[hash].js",
33+
}),
34+
);
35+
36+
const statsFilePath = path.resolve(
37+
rollupPath,
38+
"distV4/codecov-bundle-stats.json",
39+
);
40+
41+
const statsData = fs.readFileSync(statsFilePath);
42+
stats = JSON.parse(statsData.toString()) as Output;
43+
});
44+
45+
afterAll(() => {
46+
fs.rm(
47+
path.resolve(rollupPath, "distV4"),
48+
{ recursive: true, force: true },
49+
() => null,
50+
);
51+
});
52+
53+
it("matches the snapshot", () => {
54+
const statsFilePath = path.resolve(
55+
rollupPath,
56+
"distV4/codecov-bundle-stats.json",
57+
);
58+
59+
const statsData = fs.readFileSync(statsFilePath);
60+
stats = JSON.parse(statsData.toString()) as Output;
61+
62+
expect(stats).toMatchSnapshot({
63+
builtAt: expect.any(Number),
64+
duration: expect.any(Number),
65+
});
66+
});
67+
});
68+
});

0 commit comments

Comments
 (0)