Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(esbuild-meta): add tests #90

Closed
wants to merge 12 commits into from
32 changes: 30 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,34 @@ jobs:
- name: Build Affected
run: npx nx affected -t build build-storybook --parallel=3

e2e:
name: End-To-End Affected
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0
# Derive appropriate SHAs for base and head for `nx affected` commands
- uses: nrwl/nx-set-shas@v3
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Cache NPM Dependencies
uses: actions/cache@v4
with:
path: |
node_modules
~/.cache
dist
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}

- name: Build Affected
run: npx nx affected -t e2e --parallel=3 --exclude audit-runner-e2e, portal-e2e
# publish-storybook:
# name: Publish Storybook
# needs: [build, lint]
Expand Down Expand Up @@ -161,7 +189,7 @@ jobs:

deploy-front-end:
name: Deploy Front-End
needs: [build, lint]
needs: [e2e]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -203,7 +231,7 @@ jobs:

deploy-server:
name: Deploy Server
needs: [build, lint]
needs: [e2e]
runs-on: ubuntu-latest

steps:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ dist

# Nx Cache
.nx

# Temporary Files
tmp
13 changes: 13 additions & 0 deletions global-setup.e2e.ts
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');
}

export async function teardown() {
stopLocalRegistry();
execSync('npm uninstall @app-speed/esbuild-meta');
}
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"release": {
"version": {
"preVersionCommand": "npx nx run-many -t build"
}
},
"projects": ["esbuild-meta"]
},
"plugins": [
{
Expand Down
87 changes: 45 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "app-speed",
"name": "@app-speed/source",
"main": "apps/user-flow-runner/src/app/runner.ts",
"scripts": {
"start": "nx serve user-flow-manager",
Expand Down Expand Up @@ -90,6 +90,7 @@
"@vitest/coverage-v8": "1.4.0",
"@vitest/ui": "1.4.0",
"autoprefixer": "^10.4.0",
"chalk": "^5.3.0",
"chromatic": "^7.2.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"cypress": "^13.0.0",
Expand Down Expand Up @@ -123,10 +124,10 @@
"ts-jest": "29.1.0",
"typescript": "5.3.3",
"verdaccio": "^5.0.4",
"vite": "5.1.3",
"vite": "~5.0.0",
"vite-plugin-eslint": "^1.8.1",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "1.4.0",
"vitest": "^1.3.1",
"webpack": "^5.64.0"
},
"nx": {
Expand Down
11 changes: 11 additions & 0 deletions packages/esbuild-meta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [1.3.1](https://github.com/ChristopherPHolder/app-speed/compare/esbuild-meta-1.3.0...esbuild-meta-1.3.1) (2024-05-05)


### Bug Fixes

* **esbuild-meta:** add missing type ([0e7f76b](https://github.com/ChristopherPHolder/app-speed/commit/0e7f76bdd6f8e980d2f74f023fbc04833ec26685))
* **esbuild-meta:** add missing type ([973e10e](https://github.com/ChristopherPHolder/app-speed/commit/973e10ed0765a194df316d6c374125431437aa34))
* **esbuild-meta:** filter only import-statements ([da64edf](https://github.com/ChristopherPHolder/app-speed/commit/da64edf7fb8fb1eb7bd804e32ff5f9e7c617abb7))



# [1.3.0](https://github.com/ChristopherPHolder/app-speed/compare/esbuild-meta-1.2.0...esbuild-meta-1.3.0) (2024-04-18)


Expand Down
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:
--version Show version number [boolean]
-h, --help Show help [boolean]
"
`;
26 changes: 26 additions & 0 deletions packages/esbuild-meta/e2e/esbuild-meta.test.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { version } from '../package.json';

import { commandOutput } from './utils.js';

describe('--help', () => {
let helpOutput: string;

beforeAll(() => {
helpOutput = commandOutput('npx esbuild-meta --help');
});

it('should show help', () => {
expect(helpOutput).toMatchSnapshot();
});

it('should alias to -h', () => {
expect(commandOutput('npx esbuild-meta -h')).toBe(helpOutput);
});
});

describe('--version', () => {
it('should show version', () => {
expect(commandOutput('npx esbuild-meta --version')).toContain(version);
});
});
3 changes: 3 additions & 0 deletions packages/esbuild-meta/e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { execSync } from 'child_process';

export const commandOutput = (command: string) => execSync(command).toString();
10 changes: 7 additions & 3 deletions packages/esbuild-meta/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "@app-speed/esbuild-meta",
"bin": "./main.js",
"bin": {
"esbuild-meta": "./main.js"
},
"type": "module",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"esbuild": "0.19.2",
"yargs": "^17.7.2"
},
"version": "1.3.0"
"devDependencies": {
"esbuild": "0.19.2"
},
"version": "1.3.1"
}
10 changes: 7 additions & 3 deletions packages/esbuild-meta/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
"main": "packages/esbuild-meta/src/main.ts",
"tsConfig": "packages/esbuild-meta/tsconfig.lib.json",
"assets": ["packages/esbuild-meta/*.md"],
"generatePackageJson": true,
"format": ["esm"],
"minify": true,
"platform": "node",
"bundle": true,
"thirdParty": true
"bundle": true
}
},
"nx-release-publish": {
Expand All @@ -41,6 +39,12 @@
"reportsDirectory": "../../coverage/packages/esbuild-meta"
}
},
"e2e": {
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}-e2e"],
"options": { "config": "packages/esbuild-meta/vitest.config.e2e.ts" },
"dependsOn": ["build"]
},
"version": {
"executor": "@jscutlery/semver:version",
"options": {
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-meta/src/lib/filter-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ export const filterMetaCommand: FilterMetaCommandModule = {
describe: 'Filters the meta file to only include chunks required by specified entry points',
aliases: 'f',
builder: filterMetaBuilder,
handler: filterMetaHandler
handler: filterMetaHandler,
}
2 changes: 1 addition & 1 deletion packages/esbuild-meta/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function filterMetaFromEntryPoints(meta: Metafile, entryPoints: string[])
const extractedChunks = new Set<string>();
const alreadyExtractedChildren = (chunk: string) => extractedChunks.has(chunk);
const addToExtractedChunks = (chunk: string) => extractedChunks.add(chunk) && extractedChunks.add(`${chunk}.map`);
const childImportedChunks = (chunk: string) => meta['outputs'][chunk]['imports'].filter(({kind}) => kind === "import-statement" || "dynamic-import").map(({path}) => path);
const childImportedChunks = (chunk: string) => meta['outputs'][chunk]['imports'].filter(({kind}) => kind === "import-statement").map(({path}) => path);
function extractImport(chunks: string[]) {
for (const chunk of chunks) {
if (alreadyExtractedChildren(chunk)) continue;
Expand Down
Loading
Loading