Skip to content

Commit

Permalink
test(capacitor-e2e): add e2e tests for capacitor
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Oct 1, 2024
1 parent e6264c8 commit 3497768
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 3 deletions.
21 changes: 21 additions & 0 deletions e2e/capacitor-e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const baseConfig = require('../../eslint.config.js');
module.exports = [
...baseConfig,
{
files: [
'e2e/capacitor-e2e/**/*.ts',
'e2e/capacitor-e2e/**/*.tsx',
'e2e/capacitor-e2e/**/*.js',
'e2e/capacitor-e2e/**/*.jsx',
],
rules: {},
},
{
files: ['e2e/capacitor-e2e/**/*.ts', 'e2e/capacitor-e2e/**/*.tsx'],
rules: {},
},
{
files: ['e2e/capacitor-e2e/**/*.js', 'e2e/capacitor-e2e/**/*.jsx'],
rules: {},
},
];
12 changes: 12 additions & 0 deletions e2e/capacitor-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'capacitor-e2e',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/capacitor-e2e',
globalSetup: '../../tools/scripts/start-local-registry.ts',
globalTeardown: '../../tools/scripts/stop-local-registry.ts',
};
23 changes: 23 additions & 0 deletions e2e/capacitor-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "capacitor-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "e2e/capacitor-e2e/src",
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/capacitor-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
}
},
"tags": [],
"implicitDependencies": ["capacitor"]
}
59 changes: 59 additions & 0 deletions e2e/capacitor-e2e/tests/capacitor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { runNxCommandAsync, uniq } from '@nx/plugin/testing';
import { createTestProject, installPlugin } from '@nxext/e2e-utils';
import { rmSync } from 'fs';

const ansiEscapeCodeRegex = /\x1B\[[0-?]*[ -/]*[@-~]/g;

describe('capacitor-project e2e', () => {
let projectDirectory: string;
const app = uniq('capacitor');

beforeAll(async () => {
projectDirectory = createTestProject();
installPlugin(projectDirectory, 'capacitor');

await runNxCommandAsync(
`generate @nx/web:application ${app} --style=css --bundler=vite --e2eTestRunner=none --linter=none --projectNameAndRootFormat=derived --skipFormat=true`
);
await runNxCommandAsync(
`generate @nxext/capacitor:configuration --project=${app} --appName=test --appId=test --skipFormat=true`
);
});

afterAll(() => {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it('should build successfully', async () => {
const buildResults = await runNxCommandAsync(`build ${app}`);
expect(buildResults.stdout.replace(ansiEscapeCodeRegex, '')).toContain(
`Successfully ran target build for project ${app}`
);
});

it('should run tests successfully', async () => {
const testResults = await runNxCommandAsync(`test ${app}`);
expect(testResults.stdout.replace(ansiEscapeCodeRegex, '')).toContain(
`Successfully ran target test for project ${app}`
);
});

it('should run cap successfully', async () => {
const capResults = await runNxCommandAsync(`run ${app}:cap`);
expect(capResults.stdout).toContain('Usage');

const capPackageInstallResults = await runNxCommandAsync(
`run ${app}:cap --packageInstall false`
);
expect(capPackageInstallResults.stdout).toContain('Usage: cap');

const capHelpResults = await runNxCommandAsync(
`run ${app}:cap --cmd="--help"`
);
expect(capHelpResults.stdout).toContain('Usage: cap');
});
});
10 changes: 10 additions & 0 deletions e2e/capacitor-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions e2e/capacitor-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", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
3 changes: 0 additions & 3 deletions tools/scripts/start-local-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export default async () => {
gitCommit: false,
gitTag: false,
firstRelease: true,
"generatorOptionsOverrides": {
"packageRoot": "dist/{projectRoot}"
}
});
await releasePublish({
tag: 'e2e',
Expand Down

0 comments on commit 3497768

Please sign in to comment.