nx/e2e/schematics/ng-new.test.ts
ben f38bda025b feat(schematics): add cypress e2e test runner
This is enables the use of Cypress as e2e test runner for a new
application in the Nx workspace.

The Cypress command is hidden as a flag in the main application
schematics. Meaning, the only thing needed to enable this feature is to
add the `--e2eTestRunner=cypress` flag at your command when creating
a new application.
Example:
```shell
$ ng generate application myApp --e2eTestRunner=cypress
```

By default `ng e2e my-app-e2e` will start Cypress in the application
mode. You will see the desktop application and will be able to check all
the tests and run them as you which.

If you want to run the Cypress tests in headless mode (while being on CI
for example), you can do so by passing the `--headless` to the command.
  You will see all the test results live in the terminal.
  ```shell
  $ ng e2e my-app-e2e --headless
  ```

The Cypress configuration files and folders are present in the new
`my-app-e2e` folder created. Every file are written in typescript and
will be compiled into the `/dist/apps/my-app-e2e` folder before starting
Cypress.

If you need to fine tunes the options of Cypress, you can do so by
modifying directly the `cypress.json` file in the related project.

The build steps are has follow:
• compile typescript files into javascript inside the
`/dist/app/my-app-e2e` folder
• build a dev server (using the default AngularCLI dev target build)
• run Cypress with the compiled e2e files

Screenshots and Videos will be accessible respectively in
`/dist/apps/homer-app-e2e/screenshots` and
`/dist/apps/homer-app-e2e/videos`.
2018-10-25 12:14:35 -04:00

109 lines
2.8 KiB
TypeScript

import {
newApp,
newLib,
newProject,
readJson,
runCLI,
updateFile,
fileExists
} from '../utils';
describe('Nrwl Workspace', () => {
it(
'should work',
() => {
newProject();
newApp('myApp --directory=myDir');
newLib('myLib --directory=myDir');
updateFile(
'apps/my-dir/my-app/src/app/app.module.ts',
`
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyDirMyLibModule } from '@proj/my-dir/my-lib';
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule, MyDirMyLibModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
`
);
runCLI('build --aot --project=my-dir-my-app');
// running tests for the app
expect(runCLI('test --project=my-dir-my-app --no-watch')).toContain(
'Executed 3 of 3 SUCCESS'
);
// running tests for the lib
expect(runCLI('test --project=my-dir-my-lib --no-watch')).toContain(
'Executed 1 of 1 SUCCESS'
);
// e2e tests
expect(runCLI('e2e --project=my-dir-my-app-e2e')).toContain(
'Executed 1 of 1 spec SUCCESS'
);
},
1000000
);
it(
'should support router config generation (lazy)',
() => {
newProject();
newApp('myApp --directory=myDir --routing');
newLib(
'myLib --directory=myDir --routing --lazy --parentModule=apps/my-dir/my-app/src/app/app.module.ts'
);
runCLI('build --aot --project=my-dir-my-app');
expect(runCLI('test --project=my-dir-my-app --no-watch')).toContain(
'Executed 3 of 3 SUCCESS'
);
},
1000000
);
it(
'should support router config generation (eager)',
() => {
newProject();
newApp('myApp --directory=myDir --routing');
newLib(
'myLib --directory=myDir --routing --parentModule=apps/my-dir/my-app/src/app/app.module.ts'
);
runCLI('build --aot --project=my-dir-my-app');
expect(runCLI('test --project=my-dir-my-app --no-watch')).toContain(
'Executed 3 of 3 SUCCESS'
);
},
1000000
);
it(
'should not generate e2e configuration',
() => {
newProject();
newApp('myApp --e2eTestRunner=none');
// Making sure the angular.json file doesn't contain e2e project
const angularJson = readJson('angular.json');
expect(angularJson['my-app-e2e']).toBeUndefined();
// Making sure the nx.json file doesn't contain e2e project
const nxJson = readJson('angular.json');
expect(nxJson.projects['my-app-e2e']).toBeUndefined();
// Making sure the e2e folder is not created
expect(fileExists('apps/my-app-e2e')).toBeFalsy();
},
1000000
);
});