Skip to content

Commit

Permalink
test: Add E2E tests for testapp1-commonjs and testapp2-esm
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsharvey committed Jun 2, 2024
1 parent d61eb6f commit 8a0e127
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/testapp1-commonjs-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
17 changes: 17 additions & 0 deletions apps/testapp1-commonjs-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable */
export default {
displayName: 'testapp1-commonjs-e2e',
preset: '../../jest.preset.js',
setupFiles: ['<rootDir>/src/test-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/testapp1-commonjs-e2e',
};
17 changes: 17 additions & 0 deletions apps/testapp1-commonjs-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "testapp1-commonjs-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": ["testapp1-commonjs"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"jestConfig": "apps/testapp1-commonjs-e2e/jest.config.ts",
"passWithNoTests": true
},
"dependsOn": ["testapp1-commonjs:build"]
}
}
}
1 change: 1 addition & 0 deletions apps/testapp1-commonjs-e2e/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { exec, execSync } from 'child_process';
import { promisify } from 'util';

const execP = promisify(exec);

describe('testapp1-commonjs tests', () => {

it('should work correctly with @harves/nx-node-esm-plugin:node executor', () => {
const output = execSync(`./node_modules/.bin/nx run testapp1-commonjs:test-node-esm-plugin`).toString();
expect(output).toMatch(/TEST testapp1-commonjs: [^ ]+, testlib1-commonjs, testlib2-esm/);
});

it('should fail with @nx/js:node executor', async () => {
expect.assertions(1);

await expect(async () => {
const { stdout, stderr } = await execP(`./node_modules/.bin/nx run testapp1-commonjs:test-js-node`);
}).rejects.toThrow(/Cannot find package '[^']+' imported from .+testapp1-commonjs/);
});
});
13 changes: 13 additions & 0 deletions apps/testapp1-commonjs-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions apps/testapp1-commonjs-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
18 changes: 18 additions & 0 deletions apps/testapp2-esm-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
17 changes: 17 additions & 0 deletions apps/testapp2-esm-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable */
export default {
displayName: 'testapp2-esm-e2e',
preset: '../../jest.preset.js',
setupFiles: ['<rootDir>/src/test-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/testapp2-esm-e2e',
};
17 changes: 17 additions & 0 deletions apps/testapp2-esm-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "testapp2-esm-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": ["testapp2-esm"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"jestConfig": "apps/testapp2-esm-e2e/jest.config.ts",
"passWithNoTests": true
},
"dependsOn": ["testapp2-esm:build"]
}
}
}
1 change: 1 addition & 0 deletions apps/testapp2-esm-e2e/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//
20 changes: 20 additions & 0 deletions apps/testapp2-esm-e2e/src/testapp2-esm/testapp2-esm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { exec, execSync } from 'child_process';
import { promisify } from 'util';

const execP = promisify(exec);

describe('testapp2-esm tests', () => {

it('should work correctly with @harves/nx-node-esm-plugin:node executor', () => {
const output = execSync(`./node_modules/.bin/nx run testapp2-esm:test-node-esm-plugin`).toString();
expect(output).toMatch(/TEST testapp2-esm: [^ ]+, testlib1-commonjs, testlib2-esm/);
});

it('should fail with @nx/js:node executor', async () => {
expect.assertions(1);

await expect(async () => {
const { stdout, stderr } = await execP(`./node_modules/.bin/nx run testapp2-esm:test-js-node`);
}).rejects.toThrow(/Cannot find package '[^']+' imported from .+testapp2-esm/);
});
});
13 changes: 13 additions & 0 deletions apps/testapp2-esm-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions apps/testapp2-esm-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
15 changes: 15 additions & 0 deletions libs/testapp1-commonjs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
"tsConfig": "libs/testapp1-commonjs/tsconfig.lib.json",
"assets": ["libs/testapp1-commonjs/*.md"]
}
},
"test-js-node": {
"executor": "@nx/js:node",
"dependsOn": ["build"],
"options": {
"buildTarget": "build",
"watch": false
}
},
"test-node-esm-plugin": {
"executor": "@harves/nx-node-esm-plugin:node",
"dependsOn": ["build"],
"options": {
"buildTarget": "build"
}
}
}
}
15 changes: 15 additions & 0 deletions libs/testapp2-esm/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
"tsConfig": "libs/testapp2-esm/tsconfig.lib.json",
"assets": ["libs/testapp2-esm/*.md"]
}
},
"test-js-node": {
"executor": "@nx/js:node",
"dependsOn": ["build"],
"options": {
"buildTarget": "build",
"watch": false
}
},
"test-node-esm-plugin": {
"executor": "@harves/nx-node-esm-plugin:node",
"dependsOn": ["build"],
"options": {
"buildTarget": "build"
}
}
}
}

0 comments on commit 8a0e127

Please sign in to comment.