-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(esbuild-meta): add e2e test to pipeline (#94)
- Loading branch information
Showing
20 changed files
with
368 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,3 +115,6 @@ dist | |
|
||
# Nx Cache | ||
.nx | ||
|
||
# Temporaty files | ||
tmp |
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,13 @@ | ||
import { execSync } from 'child_process'; | ||
import startLocalRegistry from './tools/scripts/start-local-registry'; | ||
import stopLocalRegistry from './tools/scripts/stop-local-registry'; | ||
|
||
export async function setup() { | ||
await startLocalRegistry(); | ||
execSync('npm install -D @app-speed/esbuild-meta@e2e --force'); | ||
} | ||
|
||
export async function teardown() { | ||
stopLocalRegistry(); | ||
execSync('npm uninstall @app-speed/esbuild-meta'); | ||
} |
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
16 changes: 16 additions & 0 deletions
16
packages/esbuild-meta/e2e/__snapshots__/filter.test.e2e.ts.snap
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,16 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`filter command > should have a help option 1`] = ` | ||
"esbuild-meta filter | ||
Filters the meta file to only include chunks required by specified entry points | ||
Options: | ||
-s, --statsPath The path to the stats.json file [string] [required] | ||
-o, --outPath The path where the new file should be saved [string] [default: "initial-stats.json"] | ||
--excludeDynamicImports, --eDI Should the dynamic imports be filtered out of the output chunk imports [boolean] [default: false] | ||
-e, --entryPoints Entry points that should be considered for the bundle [array] [default: ["main-","polyfills-"]] | ||
-v, --version Show version number [boolean] | ||
-h, --help Show help [boolean] | ||
" | ||
`; |
13 changes: 13 additions & 0 deletions
13
packages/esbuild-meta/e2e/__snapshots__/root.test.e2e.ts.snap
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,13 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`--help > should show help 1`] = ` | ||
"esbuild-meta [command] | ||
Commands: | ||
esbuild-meta filter Filters the meta file to only include chunks required by specified entry points [aliases: f] | ||
Options: | ||
-v, --version Show version number [boolean] | ||
-h, --help Show help [boolean] | ||
" | ||
`; |
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,28 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { cliProcess } from './utils.js'; | ||
import { DEMAND_STATS_PATH } from '../src/lib/filter-meta.js'; | ||
import { INVALID_FILE_PATH_ERROR_MSG } from '../src/lib/utils.js'; | ||
|
||
describe('filter command', () => { | ||
it('should have a help option', async () => { | ||
const { stdout, stderr, code } = await cliProcess('esbuild-meta filter --help'); | ||
expect(stdout).toMatchSnapshot(); | ||
expect(stderr).toBeFalsy(); | ||
expect(code).toBe(0); | ||
}); | ||
|
||
it('should demand stats path option', async () => { | ||
const { stdout, stderr, code } = await cliProcess('esbuild-meta filter'); | ||
expect(stderr).toContain(DEMAND_STATS_PATH); | ||
expect(stdout).toBeFalsy(); | ||
expect(code).toBe(1); | ||
}); | ||
|
||
it('should throw if stats path does not point to a file', async () => { | ||
const INVALID_STATS_FILE = 'invalid-path.json'; | ||
const { stdout, stderr, code } = await cliProcess(`esbuild-meta filter --statsPath ${INVALID_STATS_FILE}`); | ||
expect(stderr).toContain(INVALID_FILE_PATH_ERROR_MSG('invalid-path.json')); | ||
expect(stdout).toBeFalsy(); | ||
expect(code).toBe(1); | ||
}); | ||
}); |
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,32 @@ | ||
import { describe, it, expect, beforeAll } from 'vitest'; | ||
import { version } from '../package.json'; | ||
|
||
import { cliProcess, CliProcessOutput } from './utils.js'; | ||
|
||
describe('--help', () => { | ||
let output: CliProcessOutput; | ||
|
||
beforeAll(async () => { | ||
output = await cliProcess('esbuild-meta --help'); | ||
}); | ||
|
||
it('should show help', async () => { | ||
const { stdout, stderr, code } = output; | ||
expect(stdout).toMatchSnapshot(); | ||
expect(stderr).toBeFalsy(); | ||
expect(code).toBe(0); | ||
}); | ||
|
||
it('should alias to -h', async () => { | ||
expect(await cliProcess('esbuild-meta --help')).toEqual(output); | ||
}); | ||
}); | ||
|
||
describe('--version', () => { | ||
it('should show version', async () => { | ||
const {stdout, stderr, code} = await cliProcess('esbuild-meta --version'); | ||
expect(stdout).toContain(version); | ||
expect(stderr).toBeFalsy(); | ||
expect(code).toBe(0); | ||
}); | ||
}); |
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,19 @@ | ||
import { spawn } from 'node:child_process'; | ||
|
||
export type CliProcessOutput = { | ||
stdout: string; | ||
stderr: string; | ||
code: number | null; | ||
} | ||
|
||
export const cliProcess = (command: string) => { | ||
return new Promise<CliProcessOutput>((resolve) => { | ||
const process = spawn(command, [], { stdio: 'pipe', shell: true }); | ||
|
||
let stdout = ''; | ||
let stderr = ''; | ||
process.stdout.on('data', (data) => stdout += String(data)); | ||
process.stderr.on('data', (data) => stderr += String(data)); | ||
process.on('close', code => resolve({ stdout, stderr, code })); | ||
}) | ||
} |
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
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
Oops, something went wrong.