Skip to content

Commit 9886ea9

Browse files
committed
test: fix e2e tests
1 parent 39e0d4a commit 9886ea9

File tree

12 files changed

+423
-393
lines changed

12 files changed

+423
-393
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: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ describe('nx-flutter e2e', () => {
6262

6363
const sep = process.platform === 'win32' ? '\\' : '/';
6464
await runNxCommandAsync(
65-
`generate @nxrocks/nx-flutter:create ${appName} --no-interactive`
65+
`generate @nxrocks/nx-flutter:create ${appName} --no-interactive`,
66+
{
67+
cwd: projectDirectory,
68+
}
6669
);
6770

6871
const executors = [
@@ -105,15 +108,22 @@ describe('nx-flutter e2e', () => {
105108
let totalExecutorsTime = 0;
106109
for (const executor of executors) {
107110
const start = new Date().getTime();
108-
const result = await runNxCommandAsync(`run ${appName}:${executor.name}`);
111+
const result = await runNxCommandAsync(
112+
`run ${appName}:${executor.name}`,
113+
{
114+
cwd: projectDirectory,
115+
}
116+
);
109117
const end = new Date().getTime();
110118
console.log(`${executor.name} took ${end - start}ms`);
111119
totalExecutorsTime += end - start;
112120
expect(result.stdout).toContain(executor.output);
113121
}
114122
console.log(`Total executors time: ${totalExecutorsTime}ms`);
115123

116-
expect(() => checkFilesExist(`${appName}/pubspec.yaml`)).not.toThrow();
124+
expect(() =>
125+
checkFilesExist(`${projectDirectory}/${appName}/pubspec.yaml`)
126+
).not.toThrow();
117127
}, 400000);
118128

119129
it('should create nx-flutter project with given options', async () => {
@@ -128,7 +138,10 @@ describe('nx-flutter e2e', () => {
128138
const offline = true;
129139

130140
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`
141+
`generate @nxrocks/nx-flutter:create ${appName} --org=${org} --description="${description}" --androidLanguage=${androidLanguage} --iosLanguage=${iosLanguage} --template=${template} --platforms="${platforms}" --pub=${pub} --offline=${offline} --no-interactive`,
142+
{
143+
cwd: projectDirectory,
144+
}
132145
);
133146

134147
const executors = [
@@ -138,16 +151,21 @@ describe('nx-flutter e2e', () => {
138151
];
139152

140153
for (const executor of executors) {
141-
const result = await runNxCommandAsync(`run ${appName}:${executor.name}`);
154+
const result = await runNxCommandAsync(
155+
`run ${appName}:${executor.name}`,
156+
{
157+
cwd: projectDirectory,
158+
}
159+
);
142160
expect(result.stdout).toContain(executor.output);
143161
}
144162

145163
expect(() =>
146164
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(
165+
`${projectDirectory}/${appName}/pubspec.yaml`,
166+
`${projectDirectory}/${appName}/android/build.gradle`,
167+
`${projectDirectory}/${appName}/ios/Runner.xcodeproj`,
168+
`${projectDirectory}/${appName}/android/app/src/main/java/com/tinesoft/${appName.replaceAll(
151169
'-',
152170
'_'
153171
)}/MainActivity.java`
@@ -160,10 +178,13 @@ describe('nx-flutter e2e', () => {
160178
const appName = uniq('nx-flutter-');
161179

162180
await runNxCommandAsync(
163-
`generate @nxrocks/nx-flutter:new --directory subdir/${appName} --no-interactive`
181+
`generate @nxrocks/nx-flutter:new --directory subdir/${appName} --no-interactive`,
182+
{
183+
cwd: projectDirectory,
184+
}
164185
);
165186
expect(() =>
166-
checkFilesExist(`subdir/${appName}/pubspec.yaml`)
187+
checkFilesExist(`${projectDirectory}/subdir/${appName}/pubspec.yaml`)
167188
).not.toThrow();
168189
}, 200000);
169190
});
@@ -173,9 +194,12 @@ describe('nx-flutter e2e', () => {
173194
const appName = uniq('nx-flutter-');
174195

175196
await runNxCommandAsync(
176-
`generate @nxrocks/nx-flutter:create ${appName} --tags e2etag,e2ePackage --no-interactive`
197+
`generate @nxrocks/nx-flutter:create ${appName} --tags e2etag,e2ePackage --no-interactive`,
198+
{
199+
cwd: projectDirectory,
200+
}
177201
);
178-
const project = readJson(`${appName}/project.json`);
202+
const project = readJson(`${projectDirectory}/${appName}/project.json`);
179203
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
180204
}, 200000);
181205
});

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: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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

@@ -48,9 +48,14 @@ describe('nx-ktor e2e', () => {
4848
it('should create nx-ktor', async () => {
4949
const directory = uniq('nx-ktor-');
5050
await runNxCommandAsync(
51-
`generate @nxrocks/nx-ktor:new ${directory} --no-interactive`
51+
`generate @nxrocks/nx-ktor:new ${directory} --no-interactive`,
52+
{
53+
cwd: projectDirectory,
54+
}
5255
);
53-
const resultBuild = await runNxCommandAsync(`build ${directory}`);
56+
const resultBuild = await runNxCommandAsync(`build ${directory}`, {
57+
cwd: projectDirectory,
58+
});
5459
expect(resultBuild.stdout).toContain(
5560
`Executing command: ${isWin ? 'gradlew.bat' : './gradlew'} buildFatJar`
5661
);
@@ -66,7 +71,7 @@ describe('nx-ktor e2e', () => {
6671
if (!isWin) {
6772
const execPermission = '755';
6873
expect(
69-
lstatSync(tmpProjPath(`${directory}/gradlew`)).mode &
74+
lstatSync(`${projectDirectory}/${directory}/gradlew`).mode &
7075
octal(execPermission)
7176
).toEqual(octal(execPermission));
7277
}
@@ -76,13 +81,16 @@ describe('nx-ktor e2e', () => {
7681
it('should create src in the specified directory', async () => {
7782
const directory = uniq('nx-ktor-');
7883
await runNxCommandAsync(
79-
`generate @nxrocks/nx-ktor:new --directory subdir/${directory} --no-interactive`
84+
`generate @nxrocks/nx-ktor:new --directory subdir/${directory} --no-interactive`,
85+
{
86+
cwd: projectDirectory,
87+
}
8088
);
8189
expect(() =>
8290
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
91+
`${projectDirectory}/subdir/${directory}/gradlew`,
92+
`${projectDirectory}/subdir/${directory}/build.gradle.kts`
93+
//`${projectDirectory}/subdir/${directory}/src/main/kotlin/example/com/Application.kt` FIXME: bug in the generator, the package is not being created
8694
)
8795
).not.toThrow();
8896
}, 120000);
@@ -92,9 +100,12 @@ describe('nx-ktor e2e', () => {
92100
it('should add tags to the project', async () => {
93101
const directory = uniq('nx-ktor-');
94102
await runNxCommandAsync(
95-
`generate @nxrocks/nx-ktor:new ${directory} --tags e2etag,e2ePackage --no-interactive`
103+
`generate @nxrocks/nx-ktor:new ${directory} --tags e2etag,e2ePackage --no-interactive`,
104+
{
105+
cwd: projectDirectory,
106+
}
96107
);
97-
const project = readJson(`${directory}/project.json`);
108+
const project = readJson(`${projectDirectory}/${directory}/project.json`);
98109
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
99110
}, 120000);
100111
});

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)