-
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.
feat(nx-verdaccio): add skipInstall and post script
- Loading branch information
Showing
17 changed files
with
417 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { Tree } from '@nx/devkit'; | ||
import { join } from 'node:path'; | ||
import { afterEach, expect } from 'vitest'; | ||
import { | ||
addJsLibToWorkspace, | ||
materializeTree, | ||
registerPluginInWorkspace, | ||
} from '@push-based/test-nx-utils'; | ||
import { updateProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; | ||
import { executeProcess, teardownTestFolder } from '@push-based/test-utils'; | ||
import { TARGET_ENVIRONMENT_SETUP } from '@push-based/nx-verdaccio'; | ||
|
||
describe('nx-verdaccio plugin nxv-env-setup target', () => { | ||
let tree: Tree; | ||
const projectA = 'lib-a'; | ||
const projectAE2e = `${projectA}-e2e`; | ||
const e2eProjectARoot = join('projects', projectAE2e); | ||
const baseDir = `tmp/environments/${process.env['NX_TASK_TARGET_PROJECT']}/__test__/target-env-setup`; | ||
|
||
beforeEach(async () => { | ||
tree = await addJsLibToWorkspace(projectA); | ||
await addJsLibToWorkspace(projectAE2e, tree); | ||
updateProjectConfiguration(tree, projectAE2e, { | ||
root: e2eProjectARoot, | ||
projectType: 'application', | ||
}); | ||
updateProjectConfiguration(tree, projectAE2e, { | ||
root: e2eProjectARoot, | ||
projectType: 'application', | ||
targets: { | ||
e2e: { | ||
command: "echo 'Run E2E tests'", | ||
}, | ||
}, | ||
}); | ||
registerPluginInWorkspace(tree, { | ||
plugin: '@push-based/nx-verdaccio', | ||
options: { | ||
environments: { | ||
targetNames: ['e2e'], | ||
}, | ||
}, | ||
}); | ||
await materializeTree(tree, baseDir); | ||
const { stdout } = await executeProcess({ | ||
command: 'npm', | ||
args: ['install', 'verdaccio'], | ||
cwd: baseDir, | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
// await teardownTestFolder(baseDir); | ||
}); | ||
|
||
it('should have caching enabled by default', async () => { | ||
const { stdout } = await executeProcess({ | ||
command: 'nx', | ||
args: [ | ||
'run', | ||
`${projectAE2e}:${TARGET_ENVIRONMENT_SETUP}`, | ||
'--with-deps', | ||
'--skip-nx-cache', | ||
], | ||
cwd: baseDir, | ||
}); | ||
expect(stdout).toContain('Environment setup completed'); | ||
}); | ||
}); |
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,30 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.base.json", "../../../.eslintrc.base.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": [ | ||
"error", | ||
{ | ||
"ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
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,23 @@ | ||
{ | ||
"name": "cli-custom-install-e2e", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "projects/cli-custom-install-e2e/test", | ||
"projectType": "application", | ||
"tags": ["type:e2e", "type:e2e-vi", "type:example"], | ||
"implicitDependencies": ["cli"], | ||
"targets": { | ||
"lint": {}, | ||
"nxv-env-setup": { | ||
"cache": false, | ||
"options": { | ||
"skipInstall": true, | ||
"keepServerRunning": true, | ||
"postScript": "npx tsx --tsconfig examples/e2e/cli-custom-install-e2e/tsconfig.spec.json examples/e2e/cli-custom-install-e2e/setup/exec-global-setup.ts" | ||
} | ||
}, | ||
"e2e": { | ||
"executor": "@nx/vite:test", | ||
"inputs": ["default", "^production"] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/e2e/cli-custom-install-e2e/setup/exec-global-setup.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,3 @@ | ||
import setup from './global.setup.ts'; | ||
|
||
(async () => await setup())(); |
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,74 @@ | ||
import { | ||
DEFAULT_TEST_FIXTURE_DIST, | ||
executeProcess, | ||
getTestEnvironmentRoot, | ||
objectToCliArgs, | ||
teardownTestFolder, | ||
} from '@push-based/test-utils'; | ||
import { join } from 'node:path'; | ||
import { copyFile, mkdir } from 'node:fs/promises'; | ||
|
||
export async function setup( | ||
repoPath: string, | ||
repoName: string, | ||
projectName: string | ||
) { | ||
// setup nx environment for e2e tests | ||
await executeProcess({ | ||
command: 'npx', | ||
args: objectToCliArgs({ | ||
_: ['--yes', 'create-nx-workspace'], | ||
name: repoPath, | ||
preset: 'ts-standalone', | ||
ci: 'skip', | ||
interactive: false, | ||
}), | ||
verbose: true, | ||
}); | ||
await mkdir( | ||
join( | ||
getTestEnvironmentRoot(projectName), | ||
DEFAULT_TEST_FIXTURE_DIST, | ||
repoName | ||
), | ||
{ recursive: true } | ||
); | ||
await copyFile( | ||
join(getTestEnvironmentRoot(projectName), '.npmrc'), | ||
join(repoPath, '.npmrc') | ||
); | ||
|
||
await executeProcess({ | ||
command: 'npm', | ||
args: objectToCliArgs({ | ||
_: ['install', '@push-based/cli'], | ||
save: true, | ||
}), | ||
cwd: repoPath, | ||
}); | ||
|
||
const testPath = join(repoPath, 'users.json'); | ||
await mkdir(dirname(testPath), { recursive: true }); | ||
await writeFile( | ||
testPath, | ||
JSON.stringify([{ name: 'Michael' }, { name: 'Alice' }]) | ||
); | ||
const json = JSON.parse( | ||
(await readFile(join(repoPath, 'project.json'))).toString() | ||
); | ||
await writeFile( | ||
join(repoPath, 'project.json'), | ||
JSON.stringify({ | ||
...json, | ||
targets: { | ||
...json.targets, | ||
sort: { | ||
executor: '@push-based/cli:sort', | ||
options: { | ||
filePath: 'users.json', | ||
}, | ||
}, | ||
}, | ||
}) | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
examples/e2e/cli-custom-install-e2e/setup/vitest.global.setup.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,29 @@ | ||
import { | ||
DEFAULT_TEST_FIXTURE_DIST, | ||
executeProcess, | ||
getTestEnvironmentRoot, | ||
objectToCliArgs, | ||
teardownTestFolder, | ||
} from '@push-based/test-utils'; | ||
import { join } from 'node:path'; | ||
import { copyFile, mkdir } from 'node:fs/promises'; | ||
|
||
const projectName = 'cli-custom-install-e2e'; | ||
const repoName = 'nx-ts-repo'; | ||
const repoPath = join( | ||
getTestEnvironmentRoot(projectName), | ||
DEFAULT_TEST_FIXTURE_DIST, | ||
repoName | ||
); | ||
|
||
export default async function vitestGlobalSetup() { | ||
// clean | ||
teardownTestFolder(repoPath); | ||
|
||
// setup nx environment for e2e tests | ||
setup(repoPath, repoName, projectName); | ||
|
||
return () => { | ||
return teardownTestFolder(repoPath); | ||
}; | ||
} |
41 changes: 41 additions & 0 deletions
41
examples/e2e/cli-custom-install-e2e/test/nx-target-sort.spec.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,41 @@ | ||
import { basename, dirname, join } from 'node:path'; | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { | ||
executeProcess, | ||
objectToCliArgs, | ||
getTestEnvironmentRoot, | ||
DEFAULT_TEST_FIXTURE_DIST, | ||
} from '@push-based/test-utils'; | ||
|
||
describe('Nx target - sort', () => { | ||
const projectName = 'cli-custom-install-e2e'; | ||
const envRoot = getTestEnvironmentRoot(projectName); | ||
const repoRoot = join(envRoot, DEFAULT_TEST_FIXTURE_DIST, 'nx-ts-repo'); | ||
|
||
it('should execute Nx target in nx@v19 setup', async () => { | ||
const testPath = join(repoRoot, 'users.json'); | ||
await mkdir(dirname(testPath), { recursive: true }); | ||
await writeFile( | ||
testPath, | ||
JSON.stringify([{ name: 'Michael' }, { name: 'Alice' }]) | ||
); | ||
const { code } = await executeProcess({ | ||
command: 'npx', | ||
args: objectToCliArgs({ | ||
_: ['nx', 'sort'], | ||
filePath: testPath, | ||
}), | ||
cwd: repoRoot, | ||
verbose: true, | ||
}); | ||
|
||
expect(code).toBe(0); /**/ | ||
/* | ||
const content = (await readFile(testPath)).toString(); | ||
expect(JSON.parse(content)).toStrictEqual([ | ||
{ name: 'Alice' }, | ||
{ name: 'Michael' }, | ||
]);*/ | ||
}); | ||
}); |
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 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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,27 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"types": [ | ||
"vitest/globals", | ||
"vitest/importMeta", | ||
"vite/client", | ||
"node", | ||
"vitest" | ||
] | ||
}, | ||
"include": [ | ||
"vite.config.ts", | ||
"vitest.config.ts", | ||
"setup/**/*.ts", | ||
"test/**/*.test.ts", | ||
"test/**/*.spec.ts", | ||
"test/**/*.test.tsx", | ||
"test/**/*.spec.tsx", | ||
"test/**/*.test.js", | ||
"test/**/*.spec.js", | ||
"test/**/*.test.jsx", | ||
"test/**/*.spec.jsx", | ||
"test/**/*.d.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,27 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; | ||
|
||
export default defineConfig({ | ||
root: __dirname, | ||
cacheDir: '../../../node_modules/.vite/projects/cli-custom-install-e2e', | ||
|
||
plugins: [nxViteTsPaths()], | ||
|
||
// Uncomment this if you are using workers. | ||
// worker: { | ||
// plugins: [ nxViteTsPaths() ], | ||
// }, | ||
|
||
test: { | ||
globals: true, | ||
cache: { dir: '../../../node_modules/.vitest' }, | ||
environment: 'node', | ||
include: ['test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
reporters: ['default'], | ||
coverage: { | ||
reportsDirectory: '../../../coverage/projects/cli-custom-install-e2e', | ||
provider: 'v8', | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.