-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ng generate to @cypress/schematic to generate e2e spec files (
- Loading branch information
Showing
27 changed files
with
223 additions
and
34 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
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
File renamed without changes.
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
1 change: 0 additions & 1 deletion
1
npm/cypress-schematic/src/schematics/cypress/files/cypress/plugins/index.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
npm/cypress-schematic/src/schematics/ng-add/files/cypress/plugins/index.ts
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,2 @@ | ||
// Plugins enable you to tap into, modify, or extend the internal behavior of Cypress | ||
// For more info, visit https://on.cypress.io/plugins-api |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
...ematic/src/schematics/cypress/schema.json → ...hematic/src/schematics/ng-add/schema.json
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
43 changes: 43 additions & 0 deletions
43
npm/cypress-schematic/src/schematics/ng-generate/e2e/index.spec.ts
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,43 @@ | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing' | ||
import { join, resolve } from 'path' | ||
import { expect } from 'chai' | ||
|
||
describe('@cypress/schematic:e2e ng-generate', () => { | ||
const schematicRunner = new SchematicTestRunner( | ||
'schematics', | ||
join(__dirname, '../../collection.json'), | ||
) | ||
let appTree: UnitTestTree | ||
|
||
const workspaceOptions = { | ||
name: 'workspace', | ||
newProjectRoot: 'projects', | ||
version: '12.0.0', | ||
} | ||
|
||
const appOptions = { | ||
name: 'sandbox', | ||
inlineTemplate: false, | ||
routing: false, | ||
skipTests: false, | ||
skipPackageJson: false, | ||
} | ||
|
||
beforeEach(async () => { | ||
appTree = await schematicRunner.runExternalSchematicAsync('@schematics/angular', 'workspace', workspaceOptions).toPromise() | ||
appTree = await schematicRunner.runExternalSchematicAsync('@schematics/angular', 'application', appOptions, appTree).toPromise() | ||
}) | ||
|
||
it('should create cypress files', async () => { | ||
const files = ['cypress/integration/foo.spec.ts'] | ||
const homePath = '/projects/sandbox/' | ||
|
||
return schematicRunner.runSchematicAsync('e2e', { name: 'foo' }, appTree).toPromise().then((tree) => { | ||
files.forEach((f) => { | ||
const pathToFile = resolve(homePath, f) | ||
|
||
expect(tree.exists(pathToFile), pathToFile).equal(true) | ||
}) | ||
}) | ||
}) | ||
}) |
68 changes: 68 additions & 0 deletions
68
npm/cypress-schematic/src/schematics/ng-generate/e2e/index.ts
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,68 @@ | ||
import { | ||
Rule, Tree, SchematicsException, | ||
apply, url, applyTemplates, move, | ||
chain, mergeWith, | ||
} from '@angular-devkit/schematics' | ||
|
||
import { strings, normalize, virtualFs, workspaces } from '@angular-devkit/core' | ||
|
||
import { Schema } from './schema' | ||
|
||
function createSpec (tree: Tree): workspaces.WorkspaceHost { | ||
return { | ||
async readFile (path: string): Promise<string> { | ||
const data = tree.read(path) | ||
|
||
if (!data) { | ||
throw new SchematicsException('File not found.') | ||
} | ||
|
||
return virtualFs.fileBufferToString(data) | ||
}, | ||
async writeFile (path: string, data: string): Promise<void> { | ||
return tree.overwrite(path, data) | ||
}, | ||
async isDirectory (path: string): Promise<boolean> { | ||
return !tree.exists(path) && tree.getDir(path).subfiles.length > 0 | ||
}, | ||
async isFile (path: string): Promise<boolean> { | ||
return tree.exists(path) | ||
}, | ||
} | ||
} | ||
|
||
export default function (options: Schema): Rule { | ||
return async (tree: Tree) => { | ||
const host = createSpec(tree) | ||
const { workspace } = await workspaces.readWorkspace('/', host) | ||
|
||
if (!options.project) { | ||
// @ts-ignore | ||
options.project = workspace.extensions.defaultProject | ||
} | ||
|
||
//@ts-ignore | ||
const project = workspace.projects.get(options.project) | ||
|
||
if (!project) { | ||
throw new SchematicsException(`Invalid project name: ${options.project}`) | ||
} | ||
|
||
if (options.path === undefined) { | ||
options.path = `${project.root}/cypress/integration` | ||
} | ||
|
||
const templateSource = apply(url('../files/__path__'), [ | ||
applyTemplates({ | ||
classify: strings.classify, | ||
dasherize: strings.dasherize, | ||
name: options.name, | ||
}), | ||
move(normalize(options.path as string)), | ||
]) | ||
|
||
return chain([ | ||
mergeWith(templateSource), | ||
]) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
npm/cypress-schematic/src/schematics/ng-generate/e2e/schema.json
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,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "cypress-schematics-e2e-spec", | ||
"title": "Cypress E2E Spec Options Schema", | ||
"type": "object", | ||
"properties": { | ||
"path": { | ||
"type": "string", | ||
"format": "path", | ||
"description": "The path to create the component.", | ||
"visible": false | ||
}, | ||
"project": { | ||
"type": "string", | ||
"description": "The name of the project.", | ||
"$default": { | ||
"$source": "projectName" | ||
} | ||
}, | ||
"name": { | ||
"type": "string", | ||
"description": "The name of the e2e test.", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-prompt": "What is the name of the e2e test?" | ||
} | ||
}, | ||
"required": [ | ||
"name" | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
npm/cypress-schematic/src/schematics/ng-generate/e2e/schema.ts
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,10 @@ | ||
export interface Schema { | ||
// The name of the spec. | ||
name: string | ||
|
||
// The path to create the spec. | ||
path?: string | ||
|
||
// The name of the project. | ||
project?: string | ||
} |
4 changes: 4 additions & 0 deletions
4
...s-schematic/src/schematics/ng-generate/files/__path__/__name@dasherize__.spec.ts.template
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,4 @@ | ||
describe('<%= classify(name) %>', () => { | ||
it('', () => { | ||
}); | ||
}); |
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
File renamed without changes.
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
] | ||
}, | ||
"include": [ | ||
"src/**/*_spec.ts" | ||
"src/**/*.spec.ts" | ||
], | ||
"exclude": [ | ||
"src/**/files/**/*" | ||
|