Skip to content

Commit 0376c08

Browse files
committed
test: fix e2e tests
1 parent 95af668 commit 0376c08

File tree

15 files changed

+478
-423
lines changed

15 files changed

+478
-423
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getPackageManagerCommand } from '@nx/devkit';
2+
import { uniq } from '@nx/plugin/testing';
23
import { hasNxWrapper, isNxWrapperInstalled } from '@nxrocks/common-cli';
34
import { createCLITestProject } from '@nxrocks/common/testing';
45
import { execSync } from 'child_process';
@@ -24,7 +25,8 @@ describe('create-nx-flutter', () => {
2425
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2526
projectDirectory = createCLITestProject(
2627
'create-nx-flutter',
27-
`--prjName=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
28+
`--prjName=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`,
29+
uniq('create-nx-flutter-')
2830
);
2931

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

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

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import { getPackageManagerCommand } from '@nx/devkit';
1515
describe('nx-flutter e2e', () => {
1616
let projectDirectory: string;
1717

18-
beforeAll(() => {
19-
// Cleanup the test project
20-
projectDirectory &&
18+
afterAll(() => {
19+
if (projectDirectory) {
20+
// Cleanup the test project
2121
rmSync(projectDirectory, {
2222
recursive: true,
2323
force: true,
2424
});
25+
}
26+
});
2527

26-
projectDirectory = createTestProject();
28+
beforeAll(() => {
29+
projectDirectory = createTestProject('test-project-flutter');
2730

2831
// The plugin has been built and published to a local registry in the jest globalSetup
2932
// Install the plugin built with the latest source code into the test repo
@@ -62,7 +65,10 @@ describe('nx-flutter e2e', () => {
6265

6366
const sep = process.platform === 'win32' ? '\\' : '/';
6467
await runNxCommandAsync(
65-
`generate @nxrocks/nx-flutter:create ${appName} --no-interactive`
68+
`generate @nxrocks/nx-flutter:create ${appName} --no-interactive`,
69+
{
70+
cwd: projectDirectory,
71+
}
6672
);
6773

6874
const executors = [
@@ -105,15 +111,22 @@ describe('nx-flutter e2e', () => {
105111
let totalExecutorsTime = 0;
106112
for (const executor of executors) {
107113
const start = new Date().getTime();
108-
const result = await runNxCommandAsync(`run ${appName}:${executor.name}`);
114+
const result = await runNxCommandAsync(
115+
`run ${appName}:${executor.name}`,
116+
{
117+
cwd: projectDirectory,
118+
}
119+
);
109120
const end = new Date().getTime();
110121
console.log(`${executor.name} took ${end - start}ms`);
111122
totalExecutorsTime += end - start;
112123
expect(result.stdout).toContain(executor.output);
113124
}
114125
console.log(`Total executors time: ${totalExecutorsTime}ms`);
115126

116-
expect(() => checkFilesExist(`${appName}/pubspec.yaml`)).not.toThrow();
127+
expect(() =>
128+
checkFilesExist(`${projectDirectory}/${appName}/pubspec.yaml`)
129+
).not.toThrow();
117130
}, 400000);
118131

119132
it('should create nx-flutter project with given options', async () => {
@@ -128,7 +141,10 @@ describe('nx-flutter e2e', () => {
128141
const offline = true;
129142

130143
await runNxCommandAsync(
131-
`generate @nxrocks/nx-flutter:create ${appName} --org=${org} --description="${description}" --androidLanguage=${androidLanguage} --iosLanguage=${iosLanguage} --template=${template} --platforms="${platforms}" --pub=${pub} --offline=${offline} --no-interactive`
144+
`generate @nxrocks/nx-flutter:create ${appName} --org=${org} --description="${description}" --androidLanguage=${androidLanguage} --iosLanguage=${iosLanguage} --template=${template} --platforms="${platforms}" --pub=${pub} --offline=${offline} --no-interactive`,
145+
{
146+
cwd: projectDirectory,
147+
}
132148
);
133149

134150
const executors = [
@@ -138,16 +154,21 @@ describe('nx-flutter e2e', () => {
138154
];
139155

140156
for (const executor of executors) {
141-
const result = await runNxCommandAsync(`run ${appName}:${executor.name}`);
157+
const result = await runNxCommandAsync(
158+
`run ${appName}:${executor.name}`,
159+
{
160+
cwd: projectDirectory,
161+
}
162+
);
142163
expect(result.stdout).toContain(executor.output);
143164
}
144165

145166
expect(() =>
146167
checkFilesExist(
147-
`${appName}/pubspec.yaml`,
148-
`${appName}/android/build.gradle`,
149-
`${appName}/ios/Runner.xcodeproj`,
150-
`${appName}/android/app/src/main/java/com/tinesoft/${appName.replaceAll(
168+
`${projectDirectory}/${appName}/pubspec.yaml`,
169+
`${projectDirectory}/${appName}/android/build.gradle`,
170+
`${projectDirectory}/${appName}/ios/Runner.xcodeproj`,
171+
`${projectDirectory}/${appName}/android/app/src/main/java/com/tinesoft/${appName.replaceAll(
151172
'-',
152173
'_'
153174
)}/MainActivity.java`
@@ -160,10 +181,13 @@ describe('nx-flutter e2e', () => {
160181
const appName = uniq('nx-flutter-');
161182

162183
await runNxCommandAsync(
163-
`generate @nxrocks/nx-flutter:new --directory subdir/${appName} --no-interactive`
184+
`generate @nxrocks/nx-flutter:new --directory subdir/${appName} --no-interactive`,
185+
{
186+
cwd: projectDirectory,
187+
}
164188
);
165189
expect(() =>
166-
checkFilesExist(`subdir/${appName}/pubspec.yaml`)
190+
checkFilesExist(`${projectDirectory}/subdir/${appName}/pubspec.yaml`)
167191
).not.toThrow();
168192
}, 200000);
169193
});
@@ -173,9 +197,12 @@ describe('nx-flutter e2e', () => {
173197
const appName = uniq('nx-flutter-');
174198

175199
await runNxCommandAsync(
176-
`generate @nxrocks/nx-flutter:create ${appName} --tags e2etag,e2ePackage --no-interactive`
200+
`generate @nxrocks/nx-flutter:create ${appName} --tags e2etag,e2ePackage --no-interactive`,
201+
{
202+
cwd: projectDirectory,
203+
}
177204
);
178-
const project = readJson(`${appName}/project.json`);
205+
const project = readJson(`${projectDirectory}/${appName}/project.json`);
179206
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
180207
}, 200000);
181208
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getPackageManagerCommand } from '@nx/devkit';
2+
import { uniq } from '@nx/plugin/testing';
23
import { hasNxWrapper, isNxWrapperInstalled } from '@nxrocks/common-cli';
34
import { createCLITestProject } from '@nxrocks/common-jvm/testing';
45
import { execSync } from 'child_process';
@@ -24,7 +25,8 @@ describe('create-nx-ktor', () => {
2425
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2526
projectDirectory = createCLITestProject(
2627
'create-nx-ktor',
27-
`--prjName=ktapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
28+
`--prjName=ktapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`,
29+
uniq('create-nx-ktor-')
2830
);
2931

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

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
import { getPackageManagerCommand } from '@nx/devkit';
21
import { uniq } from '@nx/plugin/testing';
32
import {
4-
createTestProject,
53
checkFilesExist,
4+
createTestProject,
65
isWin,
7-
runNxCommandAsync,
8-
readJson,
9-
tmpProjPath,
106
octal,
7+
readJson,
8+
runNxCommandAsync,
119
} from '@nxrocks/common-jvm/testing';
10+
import { getPackageManagerCommand } from '@nx/devkit';
11+
1212
import { execSync } from 'child_process';
1313
import { lstatSync, rmSync } from 'fs-extra';
1414

1515
describe('nx-ktor e2e', () => {
1616
let projectDirectory: string;
1717

18-
beforeAll(() => {
19-
// Cleanup the test project
20-
projectDirectory &&
18+
afterAll(() => {
19+
if (projectDirectory) {
20+
// Cleanup the test project
2121
rmSync(projectDirectory, {
2222
recursive: true,
2323
force: true,
2424
});
25+
}
26+
});
2527

26-
projectDirectory = createTestProject();
28+
beforeAll(() => {
29+
projectDirectory = createTestProject('test-project-ktor');
2730

2831
// The plugin has been built and published to a local registry in the jest globalSetup
2932
// Install the plugin built with the latest source code into the test repo
@@ -48,9 +51,14 @@ describe('nx-ktor e2e', () => {
4851
it('should create nx-ktor', async () => {
4952
const directory = uniq('nx-ktor-');
5053
await runNxCommandAsync(
51-
`generate @nxrocks/nx-ktor:new ${directory} --no-interactive`
54+
`generate @nxrocks/nx-ktor:new ${directory} --no-interactive`,
55+
{
56+
cwd: projectDirectory,
57+
}
5258
);
53-
const resultBuild = await runNxCommandAsync(`build ${directory}`);
59+
const resultBuild = await runNxCommandAsync(`build ${directory}`, {
60+
cwd: projectDirectory,
61+
});
5462
expect(resultBuild.stdout).toContain(
5563
`Executing command: ${isWin ? 'gradlew.bat' : './gradlew'} buildFatJar`
5664
);
@@ -66,7 +74,7 @@ describe('nx-ktor e2e', () => {
6674
if (!isWin) {
6775
const execPermission = '755';
6876
expect(
69-
lstatSync(tmpProjPath(`${directory}/gradlew`)).mode &
77+
lstatSync(`${projectDirectory}/${directory}/gradlew`).mode &
7078
octal(execPermission)
7179
).toEqual(octal(execPermission));
7280
}
@@ -76,13 +84,16 @@ describe('nx-ktor e2e', () => {
7684
it('should create src in the specified directory', async () => {
7785
const directory = uniq('nx-ktor-');
7886
await runNxCommandAsync(
79-
`generate @nxrocks/nx-ktor:new --directory subdir/${directory} --no-interactive`
87+
`generate @nxrocks/nx-ktor:new --directory subdir/${directory} --no-interactive`,
88+
{
89+
cwd: projectDirectory,
90+
}
8091
);
8192
expect(() =>
8293
checkFilesExist(
83-
`subdir/${directory}/gradlew`,
84-
`subdir/${directory}/build.gradle.kts`
85-
//`subdir/${directory}/src/main/kotlin/example/com/Application.kt` FIXME: bug in the generator, the package is not being created
94+
`${projectDirectory}/subdir/${directory}/gradlew`,
95+
`${projectDirectory}/subdir/${directory}/build.gradle.kts`
96+
//`${projectDirectory}/subdir/${directory}/src/main/kotlin/example/com/Application.kt` FIXME: bug in the generator, the package is not being created
8697
)
8798
).not.toThrow();
8899
}, 120000);
@@ -92,9 +103,12 @@ describe('nx-ktor e2e', () => {
92103
it('should add tags to the project', async () => {
93104
const directory = uniq('nx-ktor-');
94105
await runNxCommandAsync(
95-
`generate @nxrocks/nx-ktor:new ${directory} --tags e2etag,e2ePackage --no-interactive`
106+
`generate @nxrocks/nx-ktor:new ${directory} --tags e2etag,e2ePackage --no-interactive`,
107+
{
108+
cwd: projectDirectory,
109+
}
96110
);
97-
const project = readJson(`${directory}/project.json`);
111+
const project = readJson(`${projectDirectory}/${directory}/project.json`);
98112
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
99113
}, 120000);
100114
});

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ import { rmSync } from 'fs-extra';
1111
describe('nx-melos e2e', () => {
1212
let projectDirectory: string;
1313

14-
beforeAll(() => {
15-
// Cleanup the test project
16-
projectDirectory &&
14+
afterAll(() => {
15+
if (projectDirectory) {
16+
// Cleanup the test project
1717
rmSync(projectDirectory, {
1818
recursive: true,
1919
force: true,
2020
});
21+
}
22+
});
2123

22-
projectDirectory = createTestProject();
24+
beforeAll(() => {
25+
projectDirectory = createTestProject('test-project-melos');
2326

2427
// The plugin has been built and published to a local registry in the jest globalSetup
2528
// Install the plugin built with the latest source code into the test repo
@@ -47,7 +50,10 @@ describe('nx-melos e2e', () => {
4750

4851
it('should initialize melos in the workspace', async () => {
4952
await runNxCommandAsync(
50-
`generate @nxrocks/nx-melos:init --scriptNameSeparator="-" --no-interactive`
53+
`generate @nxrocks/nx-melos:init --scriptNameSeparator="-" --no-interactive`,
54+
{
55+
cwd: projectDirectory,
56+
}
5157
);
5258

5359
const scripts = [
@@ -60,14 +66,18 @@ describe('nx-melos e2e', () => {
6066
let totalExecutorsTime = 0;
6167
for (const script of scripts) {
6268
const start = new Date().getTime();
63-
const result = await runNxCommandAsync(script.name);
69+
const result = await runNxCommandAsync(script.name, {
70+
cwd: projectDirectory,
71+
});
6472
const end = new Date().getTime();
6573
console.log(`${script.name} took ${end - start}ms`);
6674
totalExecutorsTime += end - start;
6775
expect(noFormat(result.stdout)).toContain(script.output);
6876
}
6977
console.log(`Total executors time: ${totalExecutorsTime}ms`);
7078

71-
expect(() => checkFilesExist(`melos.yaml`)).not.toThrow();
79+
expect(() =>
80+
checkFilesExist(`${projectDirectory}/melos.yaml`)
81+
).not.toThrow();
7282
}, 400000);
7383
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getPackageManagerCommand } from '@nx/devkit';
2+
import { uniq } from '@nx/plugin/testing';
23
import { hasNxWrapper, isNxWrapperInstalled } from '@nxrocks/common-cli';
34
import { createCLITestProject } from '@nxrocks/common-jvm/testing';
45
import { execSync } from 'child_process';
@@ -24,7 +25,8 @@ describe('create-nx-micronaut', () => {
2425
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2526
projectDirectory = createCLITestProject(
2627
'create-nx-micronaut',
27-
`--prjName=mnapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
28+
`--prjName=mnapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`,
29+
uniq('create-nx-micronaut-')
2830
);
2931

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

0 commit comments

Comments
 (0)