Skip to content

Commit

Permalink
test: fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Dec 15, 2024
1 parent 56421a8 commit 7818232
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 38 deletions.
3 changes: 2 additions & 1 deletion e2e/nx-flutter-e2e/tests/create-nx-flutter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('create-nx-flutter', () => {
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-flutter',
`--prjName=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
`--directory=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
);

// npm ls will fail if the package is not installed properly
Expand All @@ -33,6 +33,7 @@ describe('create-nx-flutter', () => {
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
env: process.env,
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);
Expand Down
36 changes: 22 additions & 14 deletions e2e/nx-flutter-e2e/tests/nx-flutter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { uniq } from '@nx/plugin/testing';
import {
uniq,
} from '@nx/plugin/testing';
import { checkFilesExist, createTestProject, readJson, runNxCommandAsync } from '@nxrocks/common/testing';
checkFilesExist,
createTestProject,
readJson,
runNxCommandAsync,
} from '@nxrocks/common/testing';
import { execSync } from 'child_process';
import { rmSync } from 'fs-extra';

//jest.mock('enquirer'); // we mock 'enquirer' to bypass the interactive prompt
import * as enquirer from 'enquirer';
import { getPackageManagerCommand } from '@nx/devkit';

describe('nx-flutter e2e', () => {
let projectDirectory: string;
Expand All @@ -16,24 +20,28 @@ describe('nx-flutter e2e', () => {

// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(`npm install @nxrocks/[email protected]`, {
cwd: projectDirectory,
stdio: 'inherit',
env: process.env,
});
execSync(
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
{
cwd: projectDirectory,
stdio: 'inherit',
env: process.env,
}
);
});

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

it('should be installed', () => {
// npm ls will fail if the package is not installed properly
execSync('npm ls @nxrocks/nx-flutter', {
execSync(`${getPackageManagerCommand().list} @nxrocks/nx-flutter`, {
cwd: projectDirectory,
stdio: 'inherit',
});
Expand Down Expand Up @@ -154,7 +162,7 @@ describe('nx-flutter e2e', () => {
const appName = uniq('nx-flutter');

await runNxCommandAsync(
`generate @nxrocks/nx-flutter:create ${appName} --directory subdir --no-interactive`
`generate @nxrocks/nx-flutter:new --directory subdir/${appName} --no-interactive`
);
expect(() =>
checkFilesExist(`subdir/${appName}/pubspec.yaml`)
Expand Down
3 changes: 2 additions & 1 deletion e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('create-nx-ktor', () => {
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-ktor',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive --verbose=true`
`--directory=ktapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive --verbose=true`
);

// npm ls will fail if the package is not installed properly
Expand All @@ -33,6 +33,7 @@ describe('create-nx-ktor', () => {
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
env: process.env,
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-ktor-e2e/tests/nx-ktor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('nx-ktor e2e', () => {
// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
{
cwd: projectDirectory,
stdio: 'inherit',
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('nx-ktor e2e', () => {
it('should create src in the specified directory', async () => {
const prjName = uniq('nx-ktor');
await runNxCommandAsync(
`generate @nxrocks/nx-ktor:new ${prjName} --directory subdir --no-interactive`
`generate @nxrocks/nx-ktor:new --directory subdir/${prjName} --no-interactive`
);
expect(() =>
checkFilesExist(
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-melos-e2e/tests/nx-melos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('nx-melos e2e', () => {
// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
{
cwd: projectDirectory,
stdio: 'inherit',
Expand Down
3 changes: 2 additions & 1 deletion e2e/nx-micronaut-e2e/tests/create-nx-micronaut.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('create-nx-micronaut', () => {
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-micronaut',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
`--directory=mnapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
);

// npm ls will fail if the package is not installed properly
Expand All @@ -33,6 +33,7 @@ describe('create-nx-micronaut', () => {
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
env: process.env,
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-micronaut-e2e/tests/nx-micronaut.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('nx-micronaut e2e', () => {
// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
{
cwd: projectDirectory,
stdio: 'inherit',
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('nx-micronaut e2e', () => {
it('should create src in the specified directory', async () => {
const prjName = uniq('nx-micronaut');
await runNxCommandAsync(
`generate @nxrocks/nx-micronaut:new ${prjName} --directory subdir --no-interactive`
`generate @nxrocks/nx-micronaut:new --directory subdir/${prjName} --no-interactive`
);
expect(() =>
checkFilesExist(
Expand Down
3 changes: 2 additions & 1 deletion e2e/nx-quarkus-e2e/tests/create-nx-quarkus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('create-nx-quarkus', () => {
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-quarkus',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
`--directory=qkapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
);

// npm ls will fail if the package is not installed properly
Expand All @@ -33,6 +33,7 @@ describe('create-nx-quarkus', () => {
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
env: process.env,
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-quarkus-e2e/tests/nx-quarkus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('nx-quarkus e2e', () => {
// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(
`${getPackageManagerCommand().add} @nxrocks/[email protected]`,
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
{
cwd: projectDirectory,
stdio: 'inherit',
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('nx-quarkus e2e', () => {
const prjName = uniq('nx-quarkus');

await runNxCommandAsync(
`generate @nxrocks/nx-quarkus:new ${prjName} --projectType ${projectType} --directory subdir --no-interactive`
`generate @nxrocks/nx-quarkus:new --directory subdir/${prjName} --projectType ${projectType} --no-interactive`
);
expect(() =>
checkFilesExist(
Expand Down
10 changes: 4 additions & 6 deletions e2e/nx-spring-boot-e2e/tests/create-nx-spring-boot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ describe('create-nx-spring-boot', () => {
});
});

it.each`
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
it('should be installed with Nx Wrapper=$useNxWrapper', () => {
const useNxWrapper = false;
projectDirectory = createCLITestProject(
'create-nx-spring-boot',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
`--directory=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
);

// npm ls will fail if the package is not installed properly
Expand All @@ -33,6 +30,7 @@ describe('create-nx-spring-boot', () => {
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
env: process.env,
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-spring-boot-e2e/tests/nx-spring-boot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('nx-spring-boot e2e', () => {
// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
{
cwd: projectDirectory,
stdio: 'inherit',
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('nx-spring-boot e2e', () => {
const prjName = uniq('nx-spring-boot');

await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType ${projectType} --directory subdir --no-interactive`
`generate @nxrocks/nx-spring-boot:new --directory subdir/${prjName} --projectType ${projectType} --no-interactive`
);
expect(() =>
checkFilesExist(
Expand Down
2 changes: 1 addition & 1 deletion packages/common/testing/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function createCLITestProject(
execSync(
`${
getPackageManagerCommand(pkgManager).dlx
}${confirm} ${createPkgName}@${createPkgVersion} ${projectName} ${extraArgs}`,
}${confirm} ${createPkgName}@${createPkgVersion} ${projectName} ${extraArgs} --presetVersion=${createPkgVersion}`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
Expand Down
2 changes: 2 additions & 0 deletions project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
},
"populate-local-registry": {
"cache": true,
"parallelism": false,
"inputs": ["production"],
"dependsOn": ["build"],
"command": "ts-node -P ./tools/tsconfig.tools.json ./tools/scripts/populate-local-registry.ts",
"outputs": ["{workspaceRoot}/tmp/local-registry/storage"]
}
Expand Down
8 changes: 4 additions & 4 deletions tools/scripts/start-local-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function isFolderEmptySync(folderPath: string): boolean {
const relevantFiles = files.filter(file => file !== '.verdaccio-db.json');
return relevantFiles.length === 0;
} catch (error) {
console.error('Error checking folder:', error);
throw error;
return true; // we consider the folder empty if we cannot read it
}
}

Expand Down Expand Up @@ -67,9 +66,10 @@ export async function startLocalRelease(isVerbose=false) {
},
verbose: isVerbose,
});
await releasePublish({

return await releasePublish({
tag: 'e2e',
firstRelease: true,
verbose: isVerbose,
});
}
}
13 changes: 13 additions & 0 deletions tools/scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { workspaceRoot } from "@nx/devkit";
import { execFileSync } from "child_process";


const nx = require.resolve('nx');

export const execNx = (args: string[]) =>
execFileSync(nx, args, {
env: process.env,
stdio: 'inherit',
maxBuffer: 1024 * 1024 * 10,
cwd: workspaceRoot,
});

0 comments on commit 7818232

Please sign in to comment.