Skip to content

Commit 2ad8c35

Browse files
committed
chore(workspace): add e2e project for plugin-opneapi
1 parent d4e4980 commit 2ad8c35

6 files changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../eslint.config.js');
2+
3+
module.exports = [...baseConfig];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
displayName: 'plugin-openapi-e2e',
3+
preset: '../../jest.preset.js',
4+
transform: {
5+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
6+
},
7+
moduleFileExtensions: ['ts', 'js', 'html'],
8+
coverageDirectory: '../../coverage/packages/plugin-openapi-e2e',
9+
globalSetup: '../../tools/scripts/start-local-registry.ts',
10+
globalTeardown: '../../tools/scripts/stop-local-registry.ts',
11+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "plugin-openapi-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"sourceRoot": "packages/plugin-openapi-e2e/src",
6+
"implicitDependencies": ["plugin-openapi"],
7+
"targets": {
8+
"e2e": {
9+
"executor": "@nx/jest:jest",
10+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
11+
"options": {
12+
"jestConfig": "packages/plugin-openapi-e2e/jest.config.ts",
13+
"runInBand": true
14+
},
15+
"dependsOn": ["^build"]
16+
}
17+
}
18+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { execSync } from 'child_process';
2+
import { join, dirname } from 'path';
3+
import { mkdirSync, rmSync } from 'fs';
4+
5+
describe('plugin-openapi', () => {
6+
let projectDirectory: string;
7+
8+
beforeAll(() => {
9+
projectDirectory = createTestProject();
10+
11+
// The plugin has been built and published to a local registry in the jest globalSetup
12+
// Install the plugin built with the latest source code into the test repo
13+
execSync(`npm install @nx-plugin-openapi/plugin-openapi@e2e`, {
14+
cwd: projectDirectory,
15+
stdio: 'inherit',
16+
env: process.env,
17+
});
18+
});
19+
20+
afterAll(() => {
21+
// Cleanup the test project
22+
rmSync(projectDirectory, {
23+
recursive: true,
24+
force: true,
25+
});
26+
});
27+
28+
it('should be installed', () => {
29+
// npm ls will fail if the package is not installed properly
30+
execSync('npm ls @nx-plugin-openapi/plugin-openapi', {
31+
cwd: projectDirectory,
32+
stdio: 'inherit',
33+
});
34+
});
35+
});
36+
37+
/**
38+
* Creates a test project with create-nx-workspace and installs the plugin
39+
* @returns The directory where the test project was created
40+
*/
41+
function createTestProject() {
42+
const projectName = 'test-project';
43+
const projectDirectory = join(process.cwd(), 'tmp', projectName);
44+
45+
// Ensure projectDirectory is empty
46+
rmSync(projectDirectory, {
47+
recursive: true,
48+
force: true,
49+
});
50+
mkdirSync(dirname(projectDirectory), {
51+
recursive: true,
52+
});
53+
54+
execSync(
55+
`npx --yes create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive`,
56+
{
57+
cwd: dirname(projectDirectory),
58+
stdio: 'inherit',
59+
env: process.env,
60+
}
61+
);
62+
console.log(`Created test project in "${projectDirectory}"`);
63+
64+
return projectDirectory;
65+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.spec.json"
8+
}
9+
]
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": [
9+
"jest.config.ts",
10+
"src/**/*.test.ts",
11+
"src/**/*.spec.ts",
12+
"src/**/*.d.ts"
13+
]
14+
}

0 commit comments

Comments
 (0)