-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add test project generator (#69)
* feat(core): add test project generator Add a generator that creates test projects for existing apps/libs Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
- Loading branch information
1 parent
cfc2e20
commit 7f7084f
Showing
11 changed files
with
402 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Tree } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
|
||
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet'; | ||
|
||
import * as mockedProjectGenerator from '../utils/generate-test-project'; | ||
import generator from './generator'; | ||
import { NxDotnetGeneratorSchema } from './schema'; | ||
|
||
jest.mock('../utils/generate-test-project'); | ||
|
||
describe('nx-dotnet test generator', () => { | ||
let appTree: Tree; | ||
let dotnetClient: DotNetClient; | ||
|
||
const options: NxDotnetGeneratorSchema = { | ||
project: 'existing', | ||
testTemplate: 'xunit', | ||
language: 'C#', | ||
skipOutputPathManipulation: true, | ||
}; | ||
|
||
beforeEach(() => { | ||
appTree = createTreeWithEmptyWorkspace(); | ||
dotnetClient = new DotNetClient(mockDotnetFactory()); | ||
}); | ||
|
||
it('should run successfully', async () => { | ||
await generator(appTree, options, dotnetClient); | ||
}); | ||
|
||
it('should call project generator with application project type', async () => { | ||
const projectGenerator = (mockedProjectGenerator as jest.Mocked< | ||
typeof mockedProjectGenerator | ||
>).GenerateTestProject; | ||
|
||
await generator(appTree, options, dotnetClient); | ||
expect(projectGenerator).toHaveBeenCalledWith( | ||
appTree, | ||
options, | ||
dotnetClient, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Tree } from '@nrwl/devkit'; | ||
|
||
import { DotNetClient, dotnetFactory } from '@nx-dotnet/dotnet'; | ||
|
||
import { GenerateTestProject } from '../utils/generate-test-project'; | ||
import { NxDotnetGeneratorSchema } from './schema'; | ||
|
||
export default function ( | ||
host: Tree, | ||
options: NxDotnetGeneratorSchema, | ||
dotnetClient = new DotNetClient(dotnetFactory()), | ||
) { | ||
return GenerateTestProject(host, options, dotnetClient); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { NxDotnetTestGeneratorSchema } from '../../models'; | ||
|
||
export type NxDotnetGeneratorSchema = NxDotnetTestGeneratorSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"id": "@nx-dotnet/core:lib", | ||
"title": "NxDotnet Test Generator", | ||
"description": "Generate a .NET test project for an existing application or library", | ||
"type": "object", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "The existing project to generate tests for", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
} | ||
}, | ||
"testTemplate": { | ||
"type": "string", | ||
"description": "Which template should be used for creating the tests project?", | ||
"default": "nunit", | ||
"enum": ["nunit", "xunit", "mstest"], | ||
"x-prompt": { | ||
"message": "Which template should be used for creating the tests project", | ||
"type": "list", | ||
"items": [ | ||
{ "value": "nunit", "label": "NUnit 3 Test Project" }, | ||
{ "value": "xunit", "label": "xUnit Test Project" }, | ||
{ "value": "mstest", "label": "Unit Test Project" } | ||
] | ||
} | ||
}, | ||
"language": { | ||
"type": "string", | ||
"description": "Which language should the project use?", | ||
"x-prompt": { | ||
"message": "Which language should the project use?", | ||
"type": "list", | ||
"items": ["C#", "F#", "VB"] | ||
} | ||
}, | ||
"skipOutputPathManipulation": { | ||
"type": "boolean", | ||
"description": "Skip XML changes for default build path", | ||
"default": false | ||
} | ||
}, | ||
"required": ["name", "testTemplate"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.