Skip to content

Commit

Permalink
feat(nx): cypress supportFile handling
Browse files Browse the repository at this point in the history
This update the Cypress schematic to handle by default the `supportFile` option
in `cypress.json` with an example for _custom commands_.

Related to nrwl#1609
  • Loading branch information
bcabanes committed Oct 22, 2019
1 parent 5b8989f commit 5a1b15f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@angular-devkit/architect": "0.803.3",
"@angular-devkit/core": "8.3.3",
"@cypress/webpack-preprocessor": "~4.1.0",
"fork-ts-checker-webpack-plugin": "^0.4.9",
"tree-kill": "1.2.1",
"ts-loader": "5.3.1",
"tsconfig-paths-webpack-plugin": "3.2.0",
Expand Down
11 changes: 10 additions & 1 deletion packages/cypress/src/builders/cypress/cypress.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default createBuilder<CypressBuilderOptions>(run);

/**
* @whatItDoes This is the starting point of the builder.
* @param builderConfig
* @param options
* @param context
*/
function run(
options: CypressBuilderOptions,
Expand Down Expand Up @@ -96,8 +97,15 @@ function run(
* provide directly the results in the console output.
* @param cypressConfig
* @param headless
* @param exit
* @param record
* @param key
* @param parallel
* @param baseUrl
* @param isWatching
* @param browser
* @param env
* @param spec
*/
function initCypress(
cypressConfig: string,
Expand Down Expand Up @@ -159,6 +167,7 @@ function initCypress(
* @whatItDoes Compile the application using the webpack builder.
* @param devServerTarget
* @param isWatching
* @param context
* @private
*/
export function startDevServer(
Expand Down
12 changes: 4 additions & 8 deletions packages/cypress/src/plugins/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as wp from '@cypress/webpack-preprocessor';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import * as nodeExternals from 'webpack-node-externals';

import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

export function preprocessTypescript(config: any) {
if (!config.env.tsConfig) {
throw new Error(
Expand Down Expand Up @@ -39,16 +37,14 @@ export function getWebpackConfig(config: any) {
// https://github.com/TypeStrong/ts-loader/pull/685
experimentalWatchApi: true,
// https://github.com/cypress-io/cypress/issues/2316
transpileOnly: true
transpileOnly: true,
// Enable Cypress commands typings with `declare` syntax
allowDeclarations: true
}
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin({
tsconfig: config.env.tsConfig
})
],
plugins: [],
externals: [nodeExternals()]
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('schematic:cypress-project', () => {
fixturesFolder: './src/fixtures',
integrationFolder: './src/integration',
pluginsFile: './src/plugins/index',
supportFile: false,
supportFile: './src/support/index.ts',
video: true,
videosFolder: '../../dist/cypress/apps/my-app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/my-app-e2e/screenshots',
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('schematic:cypress-project', () => {
fixturesFolder: './src/fixtures',
integrationFolder: './src/integration',
pluginsFile: './src/plugins/index',
supportFile: false,
supportFile: './src/support/index.ts',
video: true,
videosFolder: '../../../dist/cypress/apps/my-dir/my-app-e2e/videos',
screenshotsFolder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"pluginsFile": "./src/plugins/index",
"supportFile": false,
"supportFile": "./src/support/index.ts",
"video": true,
"videosFolder": "<%= offsetFromRoot %>dist/cypress/<%= projectRoot %>/videos",
"screenshotsFolder": "<%= offsetFromRoot %>dist/cypress/<%= projectRoot %>/screenshots",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ describe('<%= project %>', () => {
beforeEach(() => cy.visit('/'));

it('should display welcome message', () => {
// Custom command example, see `../support/commands.ts` file
cy.login('[email protected]', 'myPassword');

// Function helper example, see `../support/app.po.ts` file
getGreeting().contains('Welcome to <%= project %>!');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
declare namespace Cypress {
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
Expand Down

0 comments on commit 5a1b15f

Please sign in to comment.