Skip to content

Commit

Permalink
e2e(examples): add e2e for each example
Browse files Browse the repository at this point in the history
  • Loading branch information
jogelin committed Dec 11, 2024
1 parent c05328f commit 2786b16
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { join } from 'node:path';
import { workspaceRoot } from 'nx/src/utils/workspace-root';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

describe('create-huge-nx e2e', () => {
const conventionsFile = join(workspaceRoot, 'examples', 'nx-preset-angular-monorepo.conventions.ts');
const conventionsFile = join(workspaceRoot, 'examples', 'nx-preset-angular-monorepo.conventions.ts');

describe(`e2e: ${conventionsFile}`, () => {
let wsName: string;
let wsCwd: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { readFileSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { workspaceRoot } from 'nx/src/utils/workspace-root';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

describe('create-huge-nx e2e', () => {
const conventionsFile = join(workspaceRoot, 'examples', 'nx-preset-angular-monorepo.conventions.ts');
const conventionsName = 'nx-preset-angular-monorepo';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

beforeEach(() => {
wsName = getWsName(conventionsFile);
wsName = getWsName(conventionsName);
wsCwd = getWsCwd(wsName);
});

Expand All @@ -27,7 +26,7 @@ describe('create-huge-nx e2e', () => {
});

it('with native create-nx-workspace defaultBase parameter', async () => {
createHugeNxWorkspace(wsName, conventionsFile, { defaultBase: 'develop' });
createHugeNxWorkspace(wsName, conventionsName, { defaultBase: 'develop' });

const results = runCommand(`nx build my-app --skip-sync`, wsCwd);
expect(stripAnsi(results)).toContain(`Successfully ran target build for project my-app`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { existsSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { workspaceRoot } from 'nx/src/utils/workspace-root';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

describe('create-huge-nx e2e', () => {
const conventionsFile = join(workspaceRoot, 'examples', 'nx-preset-angular-monorepo.conventions.ts');
const conventionsName = 'nx-preset-angular-monorepo';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

beforeEach(() => {
wsName = getWsName(conventionsFile);
wsName = getWsName(conventionsName);
wsCwd = getWsCwd(wsName);
});

Expand All @@ -27,7 +26,7 @@ describe('create-huge-nx e2e', () => {
});

it('with native create-nx-workspace packageManager parameter', async () => {
createHugeNxWorkspace(wsName, conventionsFile, { packageManager: 'pnpm' });
createHugeNxWorkspace(wsName, conventionsName, { packageManager: 'pnpm' });

const results = runCommand(`nx build my-app --skip-sync`, wsCwd);
expect(stripAnsi(results)).toContain(`Successfully ran target build for project my-app`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { readFileSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { workspaceRoot } from 'nx/src/utils/workspace-root';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

describe('create-huge-nx e2e', () => {
const conventionsFile = join(workspaceRoot, 'examples', 'nx-preset-angular-monorepo.conventions.ts');
const conventionsName = 'nx-preset-angular-monorepo';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

beforeEach(() => {
wsName = getWsName(conventionsFile);
wsName = getWsName(conventionsName);
wsCwd = getWsCwd(wsName);
});

Expand All @@ -27,7 +26,7 @@ describe('create-huge-nx e2e', () => {
});

it('with previous nx version', async () => {
createHugeNxWorkspace(wsName, conventionsFile, { nxVersion: '19' });
createHugeNxWorkspace(wsName, conventionsName, { nxVersion: '19' });

const results = runCommand(`nx build my-app --skip-sync`, wsCwd);
expect(stripAnsi(results)).toContain(`Successfully ran target build for project my-app`);
Expand Down
8 changes: 5 additions & 3 deletions e2e/examples/tests/huge-angular-full-stack.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { rmSync } from 'node:fs';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

describe('huge-angular-full-stack e2e', () => {
const conventionsName = 'huge-angular-full-stack';
import { rmSync } from 'node:fs';

const conventionsName = 'huge-angular-full-stack';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

Expand Down
37 changes: 37 additions & 0 deletions e2e/examples/tests/huge-angular-mf.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { rmSync } from 'node:fs';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

const conventionsName = 'huge-angular-mf';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

beforeEach(() => {
wsName = getWsName(conventionsName);
wsCwd = getWsCwd(wsName);
});

afterEach((context) => {
if (context.task.result.state === 'pass') {
console.log(`Remove workspace ${wsCwd}`);
rmSync(wsCwd, {
recursive: true,
force: true,
});
} else {
console.log(`Test failed - Workspace content at ${wsCwd}:`);
runCommand('ls -la', wsCwd);
}
});

it('should build successfully', async () => {
createHugeNxWorkspace(wsName, conventionsName);

const resultApp = runCommand(`nx build hotel-app --skip-sync`, wsCwd);
expect(stripAnsi(resultApp)).toContain(`Successfully ran target build for project hotel-app`);

const resultLib = runCommand(`nx build guest-data-access --skip-sync`, wsCwd);
expect(stripAnsi(resultLib)).toContain(`Successfully ran target build for project guest-data-access`);
});
});
37 changes: 37 additions & 0 deletions e2e/examples/tests/huge-next-full-stack.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { rmSync } from 'node:fs';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

const conventionsName = 'huge-next-full-stack';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

beforeEach(() => {
wsName = getWsName(conventionsName);
wsCwd = getWsCwd(wsName);
});

afterEach((context) => {
if (context.task.result.state === 'pass') {
console.log(`Remove workspace ${wsCwd}`);
rmSync(wsCwd, {
recursive: true,
force: true,
});
} else {
console.log(`Test failed - Workspace content at ${wsCwd}:`);
runCommand('ls -la', wsCwd);
}
});

it('should build successfully', async () => {
createHugeNxWorkspace(wsName, conventionsName);

const resultApp = runCommand(`nx build hotel-app --skip-sync`, wsCwd);
expect(stripAnsi(resultApp)).toContain(`Successfully ran target build for project hotel-app`);

const resultLib = runCommand(`nx build guest-data-access --skip-sync`, wsCwd);
expect(stripAnsi(resultLib)).toContain(`Successfully ran target build for project guest-data-access`);
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { rmSync } from 'node:fs';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

describe('create-huge-nx e2e', () => {
const conventionsName = 'nx-preset-angular-monorepo';
import { rmSync } from 'node:fs';

const conventionsName = 'huge-angular-full-stack';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

Expand All @@ -24,10 +26,10 @@ describe('create-huge-nx e2e', () => {
}
});

it('with conventions example name', async () => {
it('should build successfully', async () => {
createHugeNxWorkspace(wsName, conventionsName);

const results = runCommand(`nx build my-app --skip-sync`, wsCwd);
expect(stripAnsi(results)).toContain(`Successfully ran target build for project my-app`);
const resultApp = runCommand(`nx build my-app --skip-sync`, wsCwd);
expect(stripAnsi(resultApp)).toContain(`Successfully ran target build for project my-app`);
});
});
34 changes: 34 additions & 0 deletions e2e/examples/tests/nx-preset-react-monorepo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { rmSync } from 'node:fs';
import { createHugeNxWorkspace, getWsCwd, getWsName, runCommand, stripAnsi } from '@huge-nx/e2e-utils';

const conventionsName = 'nx-preset-react-monorepo';

describe(`e2e: ${conventionsName}`, () => {
let wsName: string;
let wsCwd: string;

beforeEach(() => {
wsName = getWsName(conventionsName);
wsCwd = getWsCwd(wsName);
});

afterEach((context) => {
if (context.task.result.state === 'pass') {
console.log(`Remove workspace ${wsCwd}`);
rmSync(wsCwd, {
recursive: true,
force: true,
});
} else {
console.log(`Test failed - Workspace content at ${wsCwd}:`);
runCommand('ls -la', wsCwd);
}
});

it('should build successfully', async () => {
createHugeNxWorkspace(wsName, conventionsName);

const resultApp = runCommand(`nx build my-app --skip-sync`, wsCwd);
expect(stripAnsi(resultApp)).toContain(`Successfully ran target build for project my-app`);
});
});

0 comments on commit 2786b16

Please sign in to comment.