Skip to content

Commit ef002ea

Browse files
committed
test: fix e2e tests
1 parent 0b675cc commit ef002ea

File tree

42 files changed

+153
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+153
-228
lines changed

e2e/nx-flutter-e2e/tests/create-nx-flutter.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('create-nx-flutter', () => {
2424
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2525
projectDirectory = createCLITestProject(
2626
'create-nx-flutter',
27-
`--prjName=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
27+
`--directory=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2828
);
2929

3030
// npm ls will fail if the package is not installed properly

e2e/nx-flutter-e2e/tests/nx-flutter.spec.ts

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { uniq } from '@nx/plugin/testing';
12
import {
2-
uniq,
3-
} from '@nx/plugin/testing';
4-
import { checkFilesExist, createTestProject, readJson, runNxCommandAsync } from '@nxrocks/common/testing';
3+
checkFilesExist,
4+
createTestProject,
5+
readJson,
6+
runNxCommandAsync,
7+
} from '@nxrocks/common/testing';
58
import { execSync } from 'child_process';
69
import { rmSync } from 'fs-extra';
710

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

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

1721
// The plugin has been built and published to a local registry in the jest globalSetup
1822
// Install the plugin built with the latest source code into the test repo
19-
execSync(`npm install @nxrocks/[email protected]`, {
20-
cwd: projectDirectory,
21-
stdio: 'inherit',
22-
env: process.env,
23-
});
23+
execSync(
24+
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
25+
{
26+
cwd: projectDirectory,
27+
stdio: 'inherit',
28+
env: process.env,
29+
}
30+
);
2431
});
2532

2633
afterAll(() => {
2734
// Cleanup the test project
28-
projectDirectory && rmSync(projectDirectory, {
29-
recursive: true,
30-
force: true,
31-
});
35+
projectDirectory &&
36+
rmSync(projectDirectory, {
37+
recursive: true,
38+
force: true,
39+
});
3240
});
3341

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

156164
await runNxCommandAsync(
157-
`generate @nxrocks/nx-flutter:create ${appName} --directory subdir --no-interactive`
165+
`generate @nxrocks/nx-flutter:new --directory subdir/${appName} --no-interactive`
158166
);
159167
expect(() =>
160168
checkFilesExist(`subdir/${appName}/pubspec.yaml`)

e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('create-nx-ktor', () => {
2424
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2525
projectDirectory = createCLITestProject(
2626
'create-nx-ktor',
27-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive --verbose=true`
27+
`--directory=ktapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive --verbose=true`
2828
);
2929

3030
// npm ls will fail if the package is not installed properly

e2e/nx-ktor-e2e/tests/nx-ktor.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('nx-ktor e2e', () => {
2121
// The plugin has been built and published to a local registry in the jest globalSetup
2222
// Install the plugin built with the latest source code into the test repo
2323
execSync(
24-
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
24+
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
2525
{
2626
cwd: projectDirectory,
2727
stdio: 'inherit',
@@ -78,7 +78,7 @@ describe('nx-ktor e2e', () => {
7878
it('should create src in the specified directory', async () => {
7979
const prjName = uniq('nx-ktor');
8080
await runNxCommandAsync(
81-
`generate @nxrocks/nx-ktor:new ${prjName} --directory subdir --no-interactive`
81+
`generate @nxrocks/nx-ktor:new --directory subdir/${prjName} --no-interactive`
8282
);
8383
expect(() =>
8484
checkFilesExist(

e2e/nx-melos-e2e/tests/nx-melos.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('nx-melos e2e', () => {
1616
// The plugin has been built and published to a local registry in the jest globalSetup
1717
// Install the plugin built with the latest source code into the test repo
1818
execSync(
19-
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
19+
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
2020
{
2121
cwd: projectDirectory,
2222
stdio: 'inherit',

e2e/nx-micronaut-e2e/tests/create-nx-micronaut.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('create-nx-micronaut', () => {
2424
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2525
projectDirectory = createCLITestProject(
2626
'create-nx-micronaut',
27-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
27+
`--directory=mnapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2828
);
2929

3030
// npm ls will fail if the package is not installed properly

e2e/nx-micronaut-e2e/tests/nx-micronaut.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('nx-micronaut e2e', () => {
2222
// The plugin has been built and published to a local registry in the jest globalSetup
2323
// Install the plugin built with the latest source code into the test repo
2424
execSync(
25-
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
25+
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
2626
{
2727
cwd: projectDirectory,
2828
stdio: 'inherit',
@@ -206,7 +206,7 @@ describe('nx-micronaut e2e', () => {
206206
it('should create src in the specified directory', async () => {
207207
const prjName = uniq('nx-micronaut');
208208
await runNxCommandAsync(
209-
`generate @nxrocks/nx-micronaut:new ${prjName} --directory subdir --no-interactive`
209+
`generate @nxrocks/nx-micronaut:new --directory subdir/${prjName} --no-interactive`
210210
);
211211
expect(() =>
212212
checkFilesExist(

e2e/nx-quarkus-e2e/tests/create-nx-quarkus.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('create-nx-quarkus', () => {
2424
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2525
projectDirectory = createCLITestProject(
2626
'create-nx-quarkus',
27-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
27+
`--directory=qkapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2828
);
2929

3030
// npm ls will fail if the package is not installed properly

e2e/nx-quarkus-e2e/tests/nx-quarkus.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('nx-quarkus e2e', () => {
2323
// The plugin has been built and published to a local registry in the jest globalSetup
2424
// Install the plugin built with the latest source code into the test repo
2525
execSync(
26-
`${getPackageManagerCommand().add} @nxrocks/[email protected]`,
26+
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
2727
{
2828
cwd: projectDirectory,
2929
stdio: 'inherit',
@@ -222,7 +222,7 @@ describe('nx-quarkus e2e', () => {
222222
const prjName = uniq('nx-quarkus');
223223

224224
await runNxCommandAsync(
225-
`generate @nxrocks/nx-quarkus:new ${prjName} --projectType ${projectType} --directory subdir --no-interactive`
225+
`generate @nxrocks/nx-quarkus:new --directory subdir/${prjName} --projectType ${projectType} --no-interactive`
226226
);
227227
expect(() =>
228228
checkFilesExist(

e2e/nx-spring-boot-e2e/tests/create-nx-spring-boot.spec.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ describe('create-nx-spring-boot', () => {
1717
});
1818
});
1919

20-
it.each`
21-
useNxWrapper
22-
${true}
23-
${false}
24-
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
20+
it('should be installed with Nx Wrapper=$useNxWrapper', () => {
21+
const useNxWrapper = false;
2522
projectDirectory = createCLITestProject(
2623
'create-nx-spring-boot',
27-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
24+
`--directory=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2825
);
2926

3027
// npm ls will fail if the package is not installed properly

e2e/nx-spring-boot-e2e/tests/nx-spring-boot.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('nx-spring-boot e2e', () => {
2323
// The plugin has been built and published to a local registry in the jest globalSetup
2424
// Install the plugin built with the latest source code into the test repo
2525
execSync(
26-
`${getPackageManagerCommand().install} @nxrocks/[email protected]`,
26+
`${getPackageManagerCommand().addDev} @nxrocks/[email protected]`,
2727
{
2828
cwd: projectDirectory,
2929
stdio: 'inherit',
@@ -291,7 +291,7 @@ describe('nx-spring-boot e2e', () => {
291291
const prjName = uniq('nx-spring-boot');
292292

293293
await runNxCommandAsync(
294-
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType ${projectType} --directory subdir --no-interactive`
294+
`generate @nxrocks/nx-spring-boot:new --directory subdir/${prjName} --projectType ${projectType} --no-interactive`
295295
);
296296
expect(() =>
297297
checkFilesExist(

packages/common-cli/src/lib/main.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import {
1717
createWorkspaceWithNxWrapper,
1818
getNxCommand,
1919
} from './utils';
20-
21-
// change type to ('yes' | 'github' | 'gitlab' | 'azure' | 'bitbucket-pipelines' | 'circleci' | 'skip');
22-
// and uncomment below prompt options, once https://github.com/nrwl/nx/pull/29008 is merged
23-
export type NxCloud = 'yes' | 'github' | 'circleci' | 'skip';
20+
import { NxCloud } from 'create-nx-workspace/src/utils/nx/nx-cloud';
21+
import { detectPackageManager } from '@nx/devkit';
2422

2523
export async function mainCLI(pkgName: string, stackName: string) {
2624
const pkgFolderName = pkgName.replace('@nxrocks/', '');
@@ -60,12 +58,25 @@ export async function mainCLI(pkgName: string, stackName: string) {
6058
type: 'boolean',
6159
default: process.env['NX_VERBOSE_LOGGING'] === 'true',
6260
})
61+
.option('presetVersion', {
62+
describe: 'Enable more logging information',
63+
type: 'string',
64+
default: 'latest',
65+
})
6366
)
6467
.help('help', 'Show help') as yargs.Argv<CLIArguments>
6568
).parseSync();
6669

67-
let { name, useNxWrapper, nxCloud, useGitHub } = options;
68-
const { _, $0, name: ignoredName, verbose, ...restArgs } = options;
70+
/*eslint prefer-const: ["error", {"destructuring": "all"}]*/
71+
let {
72+
name,
73+
useNxWrapper,
74+
nxCloud,
75+
useGitHub,
76+
presetVersion,
77+
verbose,
78+
...restArgs
79+
} = options;
6980

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

109-
const presetVersion = 'latest';
120+
presetVersion ??= 'latest';
110121

111122
let directory: string;
112123

@@ -155,7 +166,7 @@ export async function mainCLI(pkgName: string, stackName: string) {
155166
name,
156167
nxCloud,
157168
useGitHub,
158-
packageManager: 'npm',
169+
packageManager: detectPackageManager(process.cwd()),
159170
})
160171
)?.directory;
161172
}

packages/common-cli/src/lib/models.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { CreateWorkspaceOptions } from 'create-nx-workspace';
22

3-
43
export interface CLIArguments extends CreateWorkspaceOptions {
5-
name: string;
6-
useNxWrapper?: boolean;
7-
nxCloud: 'yes' | 'github' | 'circleci' | 'skip';
8-
interactive: boolean;
9-
verbose: boolean;
10-
$0?: string;
11-
_?: string[]
12-
}
13-
4+
useNxWrapper?: boolean;
5+
verbose?: boolean;
6+
presetVersion?: string;
7+
$0?: string;
8+
_?: string[];
9+
}

packages/common/testing/e2e/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function createCLITestProject(
8686
execSync(
8787
`${
8888
getPackageManagerCommand(pkgManager).dlx
89-
}${confirm} ${createPkgName}@${createPkgVersion} ${projectName} ${extraArgs}`,
89+
}${confirm} ${createPkgName}@${createPkgVersion} ${projectName} ${extraArgs} --presetVersion=${createPkgVersion}`,
9090
{
9191
cwd: dirname(projectDirectory),
9292
stdio: 'inherit',

packages/nx-flutter/src/generators/preset/generator.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('preset generator', () => {
1515
let tree: Tree;
1616
const options: PresetGeneratorSchema = {
1717
directory: 'testapp',
18-
prjName: 'testapp',
18+
name: 'testapp',
1919
template: 'app',
2020
};
2121

packages/nx-flutter/src/generators/preset/generator.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import {
2-
Tree,
3-
} from '@nx/devkit';
1+
import { Tree } from '@nx/devkit';
42
import { PresetGeneratorSchema } from './schema';
53
import projectGenerator from '../project/generator';
64

75
export async function presetGenerator(
86
tree: Tree,
97
options: PresetGeneratorSchema
108
) {
11-
const { prjName } = options;
12-
139
await projectGenerator(tree, {
1410
...options,
15-
name: prjName
11+
directory: options.directory ?? options.name,
1612
});
1713
}
1814

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
import { ProjectGeneratorOptions } from '../project/schema';
22

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

packages/nx-flutter/src/generators/preset/schema.json

+10-14
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
"cli": "nx",
77
"outputCapture": "pipe",
88
"properties": {
9-
"prjName": {
10-
"type": "string",
11-
"description": "Name of the project to generate.",
12-
"x-prompt": "What is the name of your project?",
13-
"pattern": "^[a-zA-Z][^:]*$",
14-
"x-priority": "important"
15-
},
169
"directory": {
1710
"type": "string",
1811
"description": "The directory of the new project.",
19-
"alias": "d",
12+
"alias": "dir",
2013
"$default": {
2114
"$source": "argv",
2215
"index": 0
2316
},
2417
"x-prompt": "Which directory do you want to create the project in?"
2518
},
19+
"name": {
20+
"type": "string",
21+
"description": "Name of the project to generate.",
22+
"alias": "projectName",
23+
"x-prompt": "What name would you like to use?",
24+
"pattern": "^[a-zA-Z][^:]*$",
25+
"x-priority": "important"
26+
},
2627
"org": {
2728
"description": "name of the ",
2829
"type": "string",
@@ -105,11 +106,6 @@
105106
"type": "string",
106107
"description": "Add tags to the project (used for linting)."
107108
},
108-
"projectNameAndRootFormat": {
109-
"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`).",
110-
"type": "string",
111-
"enum": ["as-provided", "derived"]
112-
},
113109
"pub": {
114110
"type": "boolean",
115111
"description": "Whether or not to run 'flutter pub get' after the project has been created."
@@ -123,5 +119,5 @@
123119
"description": "Whether or not to overwrite existing files when performing operations."
124120
}
125121
},
126-
"required": ["prjName", "directory"]
122+
"required": ["directory"]
127123
}

0 commit comments

Comments
 (0)