Skip to content

Commit e2db293

Browse files
authored
fix(core): test executor should fail properly (#411)
1 parent 53bdc17 commit e2db293

File tree

22 files changed

+106
-49
lines changed

22 files changed

+106
-49
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ on:
55
push:
66
branches: [master, dev]
77

8-
env:
9-
NX_BRANCH: ${{ github.event.number }}
10-
NX_RUN_GROUP: ${{ github.run_id }}
11-
128
jobs:
139
build:
1410
runs-on: ubuntu-latest

.github/workflows/pr.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
name: Run PR checks
22

33
on: pull_request
4-
5-
6-
env:
7-
NX_BRANCH: ${{ github.event.number }}
8-
NX_RUN_GROUP: ${{ github.run_id }}
94

105
jobs:
116
build:

.github/workflows/release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: Release
22

33
on: workflow_dispatch
44

5-
env:
6-
NX_BRANCH: ${{ github.event.number }}
7-
NX_RUN_GROUP: ${{ github.run_id }}
8-
95
jobs:
106
build:
117
runs-on: ubuntu-latest

.github/workflows/smoke.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ on:
55
workflow_dispatch:
66
schedule:
77
- cron: '0 0 * * *'
8-
9-
10-
env:
11-
NX_BRANCH: main
12-
NX_RUN_GROUP: smoke
138

149
jobs:
1510
smoke:

.releaserc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
'@semantic-release/exec',
3838
{
3939
prepareCmd:
40-
'npx ts-node tools/scripts/patch-package-versions ${nextRelease.version}',
40+
'npx ts-node tools/scripts/patch-package-versions --version ${nextRelease.version} --project all',
4141
publishCmd: [
4242
'npx ts-node tools/scripts/publish-all ${nextRelease.version} ${nextRelease.channel}',
4343
'nx deploy docs-site',

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('nx-dotnet e2e', () => {
6060
runCommand('git checkout -b "affected-tests"');
6161
updateFile('package.json', (f) => {
6262
const json = JSON.parse(f);
63-
json.dependencies['@nrwl/angular'] = 'latest';
63+
json.dependencies['@nrwl/angular'] = json.devDependencies['nx'];
6464
return JSON.stringify(json);
6565
});
6666
runPackageManagerInstall();
@@ -162,7 +162,11 @@ describe('nx-dotnet e2e', () => {
162162
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`,
163163
);
164164
const promise = runNxCommandAsync(`lint ${app}`).then((x) => x.stderr);
165-
await expect(promise).resolves.toContain('WHITESPACE');
165+
await expect(promise).rejects.toThrow(
166+
expect.objectContaining({
167+
message: expect.stringContaining('WHITESPACE'),
168+
}),
169+
);
166170
});
167171
});
168172

@@ -336,6 +340,7 @@ describe('nx-dotnet e2e', () => {
336340
expect(slnFile).toContain(app + '-test');
337341
});
338342
});
343+
339344
describe('inferred targets', () => {
340345
let api: string;
341346
let projectFolder: string;
@@ -386,6 +391,37 @@ describe('nx-dotnet e2e', () => {
386391
writeFileSync(join(projectFolder, 'project.json'), projectJsonContents);
387392
});
388393
});
394+
395+
describe('@nx-dotnet/core:test', () => {
396+
it('should test with xunit', () => {
397+
const appProject = uniq('app');
398+
const testProject = `${appProject}-test`;
399+
runNxCommand(
400+
`generate @nx-dotnet/core:app ${appProject} --language="C#" --template="webapi" --test-runner xunit`,
401+
);
402+
403+
expect(() => runNxCommand(`test ${testProject}`)).not.toThrow();
404+
405+
updateFile(
406+
`apps/${testProject}/UnitTest1.cs`,
407+
`using Xunit;
408+
409+
namespace Proj.${names(appProject).className}.Test;
410+
411+
public class UnitTest1
412+
{
413+
// This test should fail, as the e2e test is checking for test failures.
414+
[Fact]
415+
public void Test1()
416+
{
417+
Assert.Equal(1, 2)
418+
}
419+
}`,
420+
);
421+
422+
expect(() => runNxCommand(`test ${testProject}`)).toThrow();
423+
});
424+
});
389425
});
390426

391427
function initializeGitRepo(cwd: string) {

nx.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
{
4141
"target": "prebuild",
4242
"projects": "self"
43+
},
44+
{
45+
"target": "prebuild",
46+
"projects": "dependencies"
4347
}
4448
]
4549
},

packages/core/project.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"prebuild": {
2222
"executor": "@nrwl/workspace:run-commands",
2323
"options": {
24-
"commands": ["npx ts-node tools/scripts/patch-package-versions"]
24+
"commands": [
25+
"npx ts-node tools/scripts/patch-package-versions --project core"
26+
]
2527
}
2628
},
2729
"build": {

packages/core/src/executors/test/executor.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExecutorContext } from '@nrwl/devkit';
1+
import { ExecutorContext, logger } from '@nrwl/devkit';
22
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
33

44
import { resolve } from 'path';
@@ -29,18 +29,23 @@ export default async function runExecutor(
2929
dotnetClient.cwd = projectDirectory;
3030
const { watch, ...parsedOptions } = options;
3131

32-
const result = dotnetClient.test(
33-
resolve(appRootPath, projectFilePath),
34-
watch,
35-
parsedOptions,
36-
);
32+
try {
33+
const result = dotnetClient.test(
34+
resolve(appRootPath, projectFilePath),
35+
watch,
36+
parsedOptions,
37+
);
3738

38-
if (watch && isChildProcess(result)) {
39-
await handleChildProcessPassthrough(result);
40-
await rimraf(projectDirectory + '/bin');
41-
await rimraf(projectDirectory + '/obj');
39+
if (watch && isChildProcess(result)) {
40+
await handleChildProcessPassthrough(result);
41+
await rimraf(projectDirectory + '/bin');
42+
await rimraf(projectDirectory + '/obj');
43+
}
44+
return {
45+
success: true,
46+
};
47+
} catch (e) {
48+
logger.error(e);
49+
return { success: false };
4250
}
43-
return {
44-
success: true,
45-
};
4651
}

packages/core/src/generators/app/schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"description": "Which template should be used for creating the tests project?",
4545
"default": "nunit",
4646
"enum": ["nunit", "xunit", "mstest", "none"],
47+
"aliases": ["testRunner"],
4748
"x-prompt": {
4849
"message": "Which template should be used for creating the tests project",
4950
"type": "list",

0 commit comments

Comments
 (0)