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 7, 2024
1 parent 0b675cc commit 0a34f56
Show file tree
Hide file tree
Showing 39 changed files with 113 additions and 158 deletions.
2 changes: 1 addition & 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 Down
34 changes: 21 additions & 13 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
2 changes: 1 addition & 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 --useGitHub=false --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 Down
2 changes: 1 addition & 1 deletion 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
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
2 changes: 1 addition & 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 Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 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 Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion e2e/nx-spring-boot-e2e/tests/create-nx-spring-boot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('create-nx-spring-boot', () => {
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
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 Down
2 changes: 1 addition & 1 deletion 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
5 changes: 1 addition & 4 deletions packages/common-cli/src/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import {
createWorkspaceWithNxWrapper,
getNxCommand,
} from './utils';

// change type to ('yes' | 'github' | 'gitlab' | 'azure' | 'bitbucket-pipelines' | 'circleci' | 'skip');
// and uncomment below prompt options, once https://github.com/nrwl/nx/pull/29008 is merged
export type NxCloud = 'yes' | 'github' | 'circleci' | 'skip';
import { NxCloud } from 'create-nx-workspace/src/utils/nx/nx-cloud';

export async function mainCLI(pkgName: string, stackName: string) {
const pkgFolderName = pkgName.replace('@nxrocks/', '');
Expand Down
15 changes: 5 additions & 10 deletions packages/common-cli/src/lib/models.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { CreateWorkspaceOptions } from 'create-nx-workspace';


export interface CLIArguments extends CreateWorkspaceOptions {
name: string;
useNxWrapper?: boolean;
nxCloud: 'yes' | 'github' | 'circleci' | 'skip';
interactive: boolean;
verbose: boolean;
$0?: string;
_?: string[]
}

useNxWrapper?: boolean;
verbose: boolean;
$0?: string;
_?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('preset generator', () => {
let tree: Tree;
const options: PresetGeneratorSchema = {
directory: 'testapp',
prjName: 'testapp',
name: 'testapp',
template: 'app',
};

Expand Down
8 changes: 2 additions & 6 deletions packages/nx-flutter/src/generators/preset/generator.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {
Tree,
} from '@nx/devkit';
import { Tree } from '@nx/devkit';
import { PresetGeneratorSchema } from './schema';
import projectGenerator from '../project/generator';

export async function presetGenerator(
tree: Tree,
options: PresetGeneratorSchema
) {
const { prjName } = options;

await projectGenerator(tree, {
...options,
name: prjName
directory: options.directory ?? options.name,
});
}

Expand Down
5 changes: 1 addition & 4 deletions packages/nx-flutter/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { ProjectGeneratorOptions } from '../project/schema';

export interface PresetGeneratorSchema
extends Omit<ProjectGeneratorOptions, 'name'> {
prjName?: string; // we cannot use "projectName" nor "name" because they have special meanings in Nx
}
export type PresetGeneratorSchema = ProjectGeneratorOptions;
19 changes: 10 additions & 9 deletions packages/nx-flutter/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
"cli": "nx",
"outputCapture": "pipe",
"properties": {
"prjName": {
"type": "string",
"description": "Name of the project to generate.",
"x-prompt": "What is the name of your project?",
"pattern": "^[a-zA-Z][^:]*$",
"x-priority": "important"
},
"directory": {
"type": "string",
"description": "The directory of the new project.",
"alias": "d",
"alias": "dir",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "Which directory do you want to create the project in?"
},
"name": {
"type": "string",
"description": "Name of the project to generate.",
"alias": "projectName",
"x-prompt": "What name would you like to use?",
"pattern": "^[a-zA-Z][^:]*$",
"x-priority": "important"
},
"org": {
"description": "name of the ",
"type": "string",
Expand Down Expand Up @@ -123,5 +124,5 @@
"description": "Whether or not to overwrite existing files when performing operations."
}
},
"required": ["prjName", "directory"]
"required": ["directory"]
}
2 changes: 1 addition & 1 deletion packages/nx-flutter/src/generators/project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"directory": {
"type": "string",
"description": "The directory of the new project.",
"alias": "d",
"alias": "dir",
"$default": {
"$source": "argv",
"index": 0
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-ktor/src/generators/preset/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('preset generator', () => {
let tree: Tree;
const options: PresetGeneratorSchema = {
directory: 'ktapp',
prjName: 'ktapp',
name: 'ktapp',
groupId: 'com.tinesoft',
artifactId: 'ktapp',
buildSystem: 'MAVEN',
Expand Down
8 changes: 2 additions & 6 deletions packages/nx-ktor/src/generators/preset/generator.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {
Tree,
} from '@nx/devkit';
import { Tree } from '@nx/devkit';
import { PresetGeneratorSchema } from './schema';
import projectGenerator from '../project/generator';

export async function presetGenerator(
tree: Tree,
options: PresetGeneratorSchema
) {
const { prjName } = options;

await projectGenerator(tree, {
...options,
name: prjName
directory: options.directory ?? options.name,
});
}

Expand Down
5 changes: 1 addition & 4 deletions packages/nx-ktor/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { ProjectGeneratorOptions } from '../project/schema';

export interface PresetGeneratorSchema
extends Omit<ProjectGeneratorOptions, 'name'> {
prjName?: string; // we cannot use "projectName" nor "name" because they have special meanings in Nx
}
export type PresetGeneratorSchema = ProjectGeneratorOptions;
19 changes: 10 additions & 9 deletions packages/nx-ktor/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
"cli": "nx",
"outputCapture": "pipe",
"properties": {
"prjName": {
"type": "string",
"description": "Name of the project to generate.",
"x-prompt": "What is the name of your project?",
"pattern": "^[a-zA-Z][^:]*$",
"x-priority": "important"
},
"directory": {
"type": "string",
"description": "The directory of the new project.",
"alias": "d",
"alias": "dir",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "Which directory do you want to create the project in?"
},
"name": {
"type": "string",
"description": "Name of the project to generate.",
"alias": "projectName",
"x-prompt": "What name would you like to use?",
"pattern": "^[a-zA-Z][^:]*$",
"x-priority": "important"
},
"ktorVersion": {
"description": "Ktor version.",
"type": "string",
Expand Down Expand Up @@ -183,5 +184,5 @@
"enum": ["as-provided", "derived"]
}
},
"required": ["prjName", "directory"]
"required": ["directory"]
}
2 changes: 1 addition & 1 deletion packages/nx-ktor/src/generators/project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"directory": {
"type": "string",
"description": "The directory of the new project.",
"alias": "d",
"alias": "dir",
"$default": {
"$source": "argv",
"index": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('preset generator', () => {
let tree: Tree;
const options: PresetGeneratorSchema = {
directory: 'mnapp',
prjName: 'mnapp',
name: 'mnapp',
projectType: 'default',
basePackage: 'com.tinesoft',
buildSystem: 'MAVEN',
Expand Down
8 changes: 2 additions & 6 deletions packages/nx-micronaut/src/generators/preset/generator.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {
Tree,
} from '@nx/devkit';
import { Tree } from '@nx/devkit';
import { PresetGeneratorSchema } from './schema';
import projectGenerator from '../project/generator';

export async function presetGenerator(
tree: Tree,
options: PresetGeneratorSchema
) {
const { prjName } = options;

await projectGenerator(tree, {
...options,
name: prjName
directory: options.directory ?? options.name,
});
}

Expand Down
5 changes: 1 addition & 4 deletions packages/nx-micronaut/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { ProjectGeneratorOptions } from '../project/schema';

export interface PresetGeneratorSchema
extends Omit<ProjectGeneratorOptions, 'name'> {
prjName?: string; // we cannot use "projectName" nor "name" because they have special meanings in Nx
}
export type PresetGeneratorSchema = ProjectGeneratorOptions;
Loading

0 comments on commit 0a34f56

Please sign in to comment.