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 8, 2024
1 parent 0b675cc commit ef002ea
Show file tree
Hide file tree
Showing 42 changed files with 153 additions and 228 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
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
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
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
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
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
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
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
9 changes: 3 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 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
27 changes: 19 additions & 8 deletions packages/common-cli/src/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ 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';
import { detectPackageManager } from '@nx/devkit';

export async function mainCLI(pkgName: string, stackName: string) {
const pkgFolderName = pkgName.replace('@nxrocks/', '');
Expand Down Expand Up @@ -60,12 +58,25 @@ export async function mainCLI(pkgName: string, stackName: string) {
type: 'boolean',
default: process.env['NX_VERBOSE_LOGGING'] === 'true',
})
.option('presetVersion', {
describe: 'Enable more logging information',
type: 'string',
default: 'latest',
})
)
.help('help', 'Show help') as yargs.Argv<CLIArguments>
).parseSync();

let { name, useNxWrapper, nxCloud, useGitHub } = options;
const { _, $0, name: ignoredName, verbose, ...restArgs } = options;
/*eslint prefer-const: ["error", {"destructuring": "all"}]*/
let {
name,
useNxWrapper,
nxCloud,
useGitHub,
presetVersion,
verbose,
...restArgs
} = options;

name ||= (await text({
message: 'Where would you like to create your workspace?',
Expand Down Expand Up @@ -106,7 +117,7 @@ export async function mainCLI(pkgName: string, stackName: string) {
initialValue: false,
})) as boolean);

const presetVersion = 'latest';
presetVersion ??= 'latest';

let directory: string;

Expand Down Expand Up @@ -155,7 +166,7 @@ export async function mainCLI(pkgName: string, stackName: string) {
name,
nxCloud,
useGitHub,
packageManager: 'npm',
packageManager: detectPackageManager(process.cwd()),
})
)?.directory;
}
Expand Down
16 changes: 6 additions & 10 deletions packages/common-cli/src/lib/models.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
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;
presetVersion?: string;
$0?: string;
_?: string[];
}
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
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;
24 changes: 10 additions & 14 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 @@ -105,11 +106,6 @@
"type": "string",
"description": "Add tags to the project (used for linting)."
},
"projectNameAndRootFormat": {
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
"type": "string",
"enum": ["as-provided", "derived"]
},
"pub": {
"type": "boolean",
"description": "Whether or not to run 'flutter pub get' after the project has been created."
Expand All @@ -123,5 +119,5 @@
"description": "Whether or not to overwrite existing files when performing operations."
}
},
"required": ["prjName", "directory"]
"required": ["directory"]
}
Loading

0 comments on commit ef002ea

Please sign in to comment.