-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build, feat: Add snapshot tests (#18)
Add in initial snapshot tests for rollup, vite, and webpack.
- Loading branch information
1 parent
bc8e4ef
commit 7fcb70b
Showing
30 changed files
with
569 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { type Output } from "@codecov/bundler-plugin-core"; | ||
import { rollup } from "rollup"; | ||
// @ts-expect-error - no types | ||
import resolve from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
import { codecovRollupPlugin } from "@codecov/rollup-plugin"; | ||
|
||
const expectedStats = { | ||
version: "1", | ||
plugin: { name: "codecov-rollup-bundle-analysis-plugin", version: "1.0.0" }, | ||
builtAt: 1701788687217, | ||
duration: 7, | ||
bundler: { name: "rollup", version: "4.6.0" }, | ||
assets: [{ name: "main-Kc6Ge1DG.js", size: 216 }], | ||
chunks: [ | ||
{ | ||
id: "main", | ||
uniqueId: "0-main", | ||
entry: true, | ||
initial: false, | ||
files: ["main-Kc6Ge1DG.js"], | ||
names: ["main"], | ||
}, | ||
], | ||
modules: [ | ||
{ | ||
name: "./src/getRandomNumber.js", | ||
size: 98, | ||
chunks: ["main"], | ||
chunkUniqueIds: ["0-main"], | ||
}, | ||
{ | ||
name: "./src/main.js", | ||
size: 115, | ||
chunks: ["main"], | ||
chunkUniqueIds: ["0-main"], | ||
}, | ||
], | ||
}; | ||
|
||
describe("Generating rollup stats", () => { | ||
let stats: Output; | ||
const rollupPath = path.resolve(__dirname, "../../test-apps/rollup"); | ||
beforeAll(async () => { | ||
await rollup({ | ||
input: `${rollupPath}/src/main.js`, | ||
plugins: [ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
resolve(), | ||
commonjs(), | ||
codecovRollupPlugin({ enableBundleAnalysis: true, dryRun: true }), | ||
], | ||
}).then((bundle) => | ||
bundle.write({ | ||
dir: `${rollupPath}/dist`, | ||
entryFileNames: "[name]-[hash].js", | ||
}), | ||
); | ||
|
||
const statsFilePath = path.resolve( | ||
rollupPath, | ||
"dist/codecov-bundle-stats.json", | ||
); | ||
|
||
const statsData = fs.readFileSync(statsFilePath); | ||
stats = JSON.parse(statsData.toString()) as Output; | ||
}); | ||
|
||
afterAll(() => { | ||
fs.rm( | ||
path.resolve(rollupPath, "dist"), | ||
{ recursive: true, force: true }, | ||
() => null, | ||
); | ||
}); | ||
|
||
it("sets the correct version", () => { | ||
expect(stats.version).toStrictEqual(expectedStats.version); | ||
}); | ||
|
||
it("sets the correct plugin information", () => { | ||
expect(stats.plugin).toStrictEqual(expectedStats.plugin); | ||
}); | ||
|
||
it("sets the correct bundler information", () => { | ||
expect(stats.bundler).toStrictEqual(expectedStats.bundler); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { type Output } from "@codecov/bundler-plugin-core"; | ||
import { build } from "vite"; | ||
import { codecovVitePlugin } from "@codecov/vite-plugin"; | ||
|
||
const expectedStats = { | ||
version: "1", | ||
plugin: { name: "codecov-vite-bundle-analysis-plugin", version: "1.0.0" }, | ||
builtAt: 1701788687217, | ||
duration: 7, | ||
bundler: { name: "rollup", version: "4.6.0" }, | ||
assets: [{ name: "main-Kc6Ge1DG.js", size: 216 }], | ||
chunks: [ | ||
{ | ||
id: "main", | ||
uniqueId: "0-main", | ||
entry: true, | ||
initial: false, | ||
files: ["main-Kc6Ge1DG.js"], | ||
names: ["main"], | ||
}, | ||
], | ||
modules: [ | ||
{ | ||
name: "./src/getRandomNumber.js", | ||
size: 98, | ||
chunks: ["main"], | ||
chunkUniqueIds: ["0-main"], | ||
}, | ||
{ | ||
name: "./src/main.js", | ||
size: 115, | ||
chunks: ["main"], | ||
chunkUniqueIds: ["0-main"], | ||
}, | ||
], | ||
}; | ||
|
||
describe("Generating vite stats", () => { | ||
let stats: Output; | ||
const vitePath = path.resolve(__dirname, "../../test-apps/vite"); | ||
beforeAll(async () => { | ||
await build({ | ||
clearScreen: false, | ||
root: vitePath, | ||
build: { | ||
outDir: "dist", | ||
rollupOptions: { | ||
input: `${vitePath}/index.html`, | ||
output: { | ||
format: "cjs", | ||
}, | ||
}, | ||
}, | ||
plugins: [ | ||
codecovVitePlugin({ enableBundleAnalysis: true, dryRun: true }), | ||
], | ||
}); | ||
|
||
const statsFilePath = path.resolve( | ||
vitePath, | ||
"dist/codecov-bundle-stats.json", | ||
); | ||
|
||
const statsData = fs.readFileSync(statsFilePath); | ||
stats = JSON.parse(statsData.toString()) as Output; | ||
}); | ||
|
||
afterAll(() => { | ||
fs.rm( | ||
path.resolve(vitePath, "dist"), | ||
{ recursive: true, force: true }, | ||
() => null, | ||
); | ||
}); | ||
|
||
it("sets the correct version", () => { | ||
expect(stats.version).toStrictEqual(expectedStats.version); | ||
}); | ||
|
||
it("sets the correct plugin information", () => { | ||
expect(stats.plugin).toStrictEqual(expectedStats.plugin); | ||
}); | ||
|
||
it("sets the correct bundler information", () => { | ||
expect(stats.bundler).toStrictEqual(expectedStats.bundler); | ||
}); | ||
}); |
98 changes: 98 additions & 0 deletions
98
integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { type Output } from "@codecov/bundler-plugin-core"; | ||
import { webpack } from "webpack"; | ||
import { codecovWebpackPlugin } from "@codecov/webpack-plugin"; | ||
|
||
const expectedStats = { | ||
version: "1", | ||
plugin: { name: "codecov-webpack-bundle-analysis-plugin", version: "1.0.0" }, | ||
builtAt: 1701788687217, | ||
duration: 7, | ||
bundler: { name: "webpack", version: "5.89.0" }, | ||
assets: [{ name: "main-Kc6Ge1DG.js", size: 216 }], | ||
chunks: [ | ||
{ | ||
id: "main", | ||
uniqueId: "0-main", | ||
entry: true, | ||
initial: false, | ||
files: ["main-Kc6Ge1DG.js"], | ||
names: ["main"], | ||
}, | ||
], | ||
modules: [ | ||
{ | ||
name: "./src/getRandomNumber.js", | ||
size: 98, | ||
chunks: ["main"], | ||
chunkUniqueIds: ["0-main"], | ||
}, | ||
{ | ||
name: "./src/main.js", | ||
size: 115, | ||
chunks: ["main"], | ||
chunkUniqueIds: ["0-main"], | ||
}, | ||
], | ||
}; | ||
|
||
describe("Generating webpack stats", () => { | ||
let stats: Output; | ||
const webpackPath = path.resolve(__dirname, "../../test-apps/webpack"); | ||
beforeAll(async () => { | ||
await new Promise<void>((resolve) => { | ||
webpack( | ||
{ | ||
cache: false, | ||
entry: `${webpackPath}/src/main.js`, | ||
output: { | ||
path: `${webpackPath}/dist`, | ||
filename: "main-[hash].js", | ||
}, | ||
mode: "production", | ||
plugins: [ | ||
codecovWebpackPlugin({ enableBundleAnalysis: true, dryRun: true }), | ||
], | ||
}, | ||
(err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
resolve(); | ||
}, | ||
); | ||
}); | ||
|
||
const statsFilePath = path.resolve( | ||
webpackPath, | ||
"dist/codecov-bundle-stats.json", | ||
); | ||
|
||
const statsData = fs.readFileSync(statsFilePath); | ||
stats = JSON.parse(statsData.toString()) as Output; | ||
}); | ||
|
||
afterAll(() => { | ||
fs.rm( | ||
path.resolve(webpackPath, "dist"), | ||
{ recursive: true, force: true }, | ||
() => null, | ||
); | ||
}); | ||
|
||
it("sets the correct version", () => { | ||
expect(stats.version).toStrictEqual(expectedStats.version); | ||
}); | ||
|
||
it("sets the correct plugin information", () => { | ||
expect(stats.plugin).toStrictEqual(expectedStats.plugin); | ||
}); | ||
|
||
it("sets the correct bundler information", () => { | ||
expect(stats.bundler).toStrictEqual(expectedStats.bundler); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,6 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const packageJson = require("./package.json") as { version: string }; | ||
|
||
const config = { | ||
module.exports = { | ||
testEnvironment: "node", | ||
collectCoverageFrom: ["!**/node_modules/**"], | ||
transform: { | ||
"^.+\\.(t|j)sx?$": [ | ||
"@swc/jest", | ||
{ | ||
jsc: { | ||
transform: { | ||
optimizer: { | ||
globals: { | ||
vars: { | ||
__PACKAGE_VERSION__: packageJson.version, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
"^.+\\.(t|j)sx?$": ["@swc/jest"], | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.