Skip to content

Commit

Permalink
ci: setup custom path matcher for vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton authored Nov 8, 2024
2 parents afdc003 + db7f113 commit c771255
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 169 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest] # @TODO add windows-latest after we have the os agnostic macher
os: [ubuntu-latest, macos-latest, windows-latest] # @TODO add windows-latest after we have the os agnostic macher
name: Unit tests
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -66,13 +66,13 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Unit test affected projects
run: npx nx affected -t unit-test --parallel=3 --verbose --coverage.enabled
run: npx nx affected -t unit-test --parallel=3 --coverage.enabled

e2e:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest] # @TODO add windows-latest after we know why it is running forever
os: [ubuntu-latest, macos-latest, windows-latest] # @TODO add windows-latest after we know why it is running forever
name: E2E tests
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -90,4 +90,4 @@ jobs:
- name: Install dependencies
run: npm i
- name: E2E test affected projects
run: NX_DAEMON=false; npx nx affected -t nxv-e2e --exclude="tag:type:example" --skipNxCache --verbose
run: npx nx affected -t nxv-e2e --exclude="tag:type:example" --skipNxCache --verbose
Original file line number Diff line number Diff line change
@@ -1,114 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to project with targetName e2e dynamically 1`] = `
{
"e2e": {
"configurations": {},
"dependsOn": [
{
"params": "forward",
"target": "nxv-env-setup",
},
],
"executor": "nx:noop",
"options": {},
"parallelism": true,
},
"nxv-e2e": {
"configurations": {},
"dependsOn": [
{
"params": "forward",
"target": "e2e",
},
],
"executor": "@push-based/nx-verdaccio:env-teardown",
"options": {},
"parallelism": true,
},
"nxv-env-bootstrap": {
"configurations": {},
"executor": "@push-based/nx-verdaccio:env-bootstrap",
"options": {},
"parallelism": true,
},
"nxv-env-install": {
"configurations": {},
"dependsOn": [
{
"params": "forward",
"projects": "dependencies",
"target": "nxv-pkg-install",
},
],
"executor": "nx:run-commands",
"options": {
"command": "echo "dependencies installed for tmp/environments/lib-a-e2e"",
"environmentRoot": "tmp/environments/lib-a-e2e",
},
"parallelism": true,
},
"nxv-env-setup": {
"cache": true,
"configurations": {},
"executor": "@push-based/nx-verdaccio:env-setup",
"inputs": [
"{projectRoot}/project.json",
{
"runtime": "node --version",
},
{
"runtime": "npm --version",
},
{
"externalDependencies": [
"verdaccio",
],
},
"^production",
],
"options": {},
"outputs": [
"{options.environmentRoot}/.npmrc",
"{options.environmentRoot}/package.json",
"{options.environmentRoot}/package-lock.json",
"{options.environmentRoot}/node_modules",
],
"parallelism": true,
},
"nxv-env-teardown": {
"configurations": {},
"executor": "@push-based/nx-verdaccio:env-teardown",
"options": {},
"parallelism": true,
},
"nxv-verdaccio-start": {
"configurations": {},
"executor": "@nx/js:verdaccio",
"options": {
"clear": true,
"config": ".verdaccio/config.yml",
"environmentDir": "tmp/environments/lib-a-e2e",
"port": Any<Number>,
"projectName": "lib-a-e2e",
"storage": "tmp/environments/lib-a-e2e/storage",
},
"outputs": [
"{options.environmentRoot}/storage",
],
"parallelism": true,
},
"nxv-verdaccio-stop": {
"configurations": {},
"executor": "@push-based/nx-verdaccio:kill-process",
"options": {
"filePath": "tmp/environments/verdaccio-registry.json",
},
"parallelism": true,
},
}
`;
exports[`nx-verdaccio plugin create-nodes-v2 > should add package targets to library project 1`] = `
{
"nxv-pkg-install": {
Expand Down
28 changes: 11 additions & 17 deletions e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
const { code, projectJson } = await nxShowProjectJson(cwd, projectAE2e);
expect(code).toBe(0);

expect(projectJson.targets).toEqual(
expect(projectJson.targets).toStrictEqual(
expect.objectContaining({
e2e: expect.objectContaining({
configurations: {},
dependsOn: [
{
params: 'forward',
Expand All @@ -210,9 +211,10 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
],
executor: 'nx:run-commands',
options: {
environmentRoot: 'tmp/environments/lib-a-e2e',
command:
'echo "dependencies installed for tmp/environments/lib-a-e2e"',
environmentRoot: expect.toMatchPath('tmp/environments/lib-a-e2e'),
command: expect.stringContaining(
'echo "dependencies installed for'
),
},
}),
[TARGET_ENVIRONMENT_SETUP]: expect.objectContaining({
Expand Down Expand Up @@ -244,16 +246,18 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
options: expect.objectContaining({
clear: true,
config: '.verdaccio/config.yml',
environmentDir: 'tmp/environments/lib-a-e2e',
environmentDir: expect.toMatchPath('tmp/environments/lib-a-e2e'),
port: expect.any(Number), // random port number
projectName: 'lib-a-e2e',
storage: 'tmp/environments/lib-a-e2e/storage',
storage: expect.toMatchPath('tmp/environments/lib-a-e2e/storage'),
}),
}),
[TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.objectContaining({
executor: '@push-based/nx-verdaccio:kill-process',
options: {
filePath: 'tmp/environments/verdaccio-registry.json',
filePath: expect.toMatchPath(
'tmp/environments/verdaccio-registry.json'
),
},
}),
[TARGET_ENVIRONMENT_E2E]: expect.objectContaining({
Expand All @@ -271,16 +275,6 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
})
);

expect({
...projectJson.targets,
[TARGET_ENVIRONMENT_VERDACCIO_START]: {
...projectJson.targets?.[TARGET_ENVIRONMENT_VERDACCIO_START],
options: {
...projectJson.targets?.[TARGET_ENVIRONMENT_VERDACCIO_START].options,
port: expect.any(Number),
},
},
}).toMatchSnapshot();
});

it('should NOT add environment targets to project without targetName e2e', async () => {
Expand Down
1 change: 1 addition & 0 deletions e2e/nx-verdaccio-e2e/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export default defineConfig({
reportsDirectory: '../../coverage/projects/nx-verdaccio-e2e',
provider: 'v8',
},
setupFiles: ['../../testing/test-setup/src/lib/extend/path-matcher.ts'],
},
});
17 changes: 15 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"@nx/nx-darwin-arm64": "^19.6.6",
"@nx/nx-darwin-x64": "^19.6.6",
"@nx/nx-linux-x64-gnu": "^19.6.6",
"@rollup/rollup-linux-x64-gnu": "^4.24.0"
"@rollup/rollup-linux-x64-gnu": "^4.24.0",
"@rollup/rollup-win32-x64-msvc": "^4.24.0"
},
"nx": {
"includedScripts": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('bootstrapEnvironment', () => {
//environmentRoot: 'tmp/environments/my-lib-e2e',
//keepServerRunning: true,
projectName: 'my-lib-e2e',
storage: 'tmp/environments/my-lib-e2e/storage',
storage: expect.toMatchPath('tmp/environments/my-lib-e2e/storage'),
readyWhen: 'Environment ready under',
verbose: undefined,
});

expect(setupNpmWorkspaceSpy).toHaveBeenCalledTimes(1);
expect(setupNpmWorkspaceSpy).toHaveBeenCalledWith(
'tmp/environments/my-lib-e2e',
expect.toMatchPath('tmp/environments/my-lib-e2e'),
undefined
);

Expand All @@ -85,14 +85,14 @@ describe('bootstrapEnvironment', () => {
host: 'localhost',
port: 4387,
url: 'http://localhost:4873',
userconfig: 'tmp/environments/my-lib-e2e/.npmrc',
userconfig: expect.toMatchPath('tmp/environments/my-lib-e2e/.npmrc'),
},
undefined
);

expect(writeFileSpy).toHaveBeenCalledTimes(1);
expect(writeFileSpy).toHaveBeenCalledWith(
'tmp/environments/my-lib-e2e/verdaccio-registry.json',
expect.toMatchPath('tmp/environments/my-lib-e2e/verdaccio-registry.json'),
JSON.stringify(
{
host: 'localhost',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ describe('runBootstrapExecutor', () => {
expect(runExecutorSpy).toHaveBeenCalledWith(
stopVerdaccioTask,
{
filePath: `tmp/environments/${e2eProjectName}/verdaccio-registry.json`,
filePath: expect.toMatchPath(
`tmp/environments/${e2eProjectName}/verdaccio-registry.json`
),
verbose: true,
},
context
Expand All @@ -122,7 +124,9 @@ describe('runBootstrapExecutor', () => {
expect(runExecutorSpy).toHaveBeenCalledWith(
stopVerdaccioTask,
{
filePath: `${environmentRoot}/verdaccio-registry.json`,
filePath: expect.toMatchPath(
`${environmentRoot}/verdaccio-registry.json`
),
},
context
);
Expand Down
17 changes: 3 additions & 14 deletions projects/nx-verdaccio/src/executors/env-setup/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
TARGET_ENVIRONMENT_INSTALL,
} from '../../plugin/targets/environment.targets';
import { runSingleExecutor } from '../../internal/run-executor';
import { rm } from 'node:fs/promises';
import { getEnvironmentRoot } from '../../internal/environment-root';
import {cleanupEnv} from "../internal/cleanup-env";

export type ExecutorOutput = {
success: boolean;
Expand Down Expand Up @@ -92,19 +92,8 @@ export default async function runSetupEnvironmentExecutor(
configuration,
environmentRoot,
});
// delete storage, npmrc
await rm(join(environmentRoot, 'storage'), {
recursive: true,
force: true,
retryDelay: 100,
maxRetries: 2,
});
await rm(join(environmentRoot, '.npmrc'), {
recursive: true,
force: true,
retryDelay: 100,
maxRetries: 2,
});
// delete storage, .npmrc
await cleanupEnv(environmentRoot)
} else {
const { url } = await readFile(
join(environmentRoot, VERDACCIO_REGISTRY_JSON),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ describe('runSetupEnvironmentExecutor', () => {
target: TARGET_ENVIRONMENT_VERDACCIO_STOP,
},
{
filePath: 'tmp/environments/my-lib-e2e/verdaccio-registry.json',
filePath: expect.toMatchPath(
'tmp/environments/my-lib-e2e/verdaccio-registry.json'
),
verbose: undefined,
},
context
Expand Down
18 changes: 18 additions & 0 deletions projects/nx-verdaccio/src/executors/internal/cleanup-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {rm} from "node:fs/promises";
import {join} from "node:path";

export async function cleanupEnv(environmentRoot: string) {
// delete storage, .npmrc
await rm(join(environmentRoot, 'storage'), {
recursive: true,
force: true,
retryDelay: 100,
maxRetries: 2,
});
await rm(join(environmentRoot, '.npmrc'), {
recursive: true,
force: true,
retryDelay: 100,
maxRetries: 2,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('runKillProcessExecutor', () => {
await expect(
runKillProcessExecutor(
{
filePath: 'tmp/environments/my-lib',
filePath: expect.toMatchPath('tmp/environments/my-lib'),
},
{
root: 'tmp/environments/test',
Expand Down
Loading

0 comments on commit c771255

Please sign in to comment.