Skip to content

Commit

Permalink
Set up Cypress component testing.
Browse files Browse the repository at this point in the history
I had to do manually:

* Add command `npx nx ct` into `angular.json`.
* Configure video and screenshot folder paths so they are automatically git ignored.
  • Loading branch information
rkrisztian committed Jun 25, 2021
1 parent ced502d commit 2f18cd4
Show file tree
Hide file tree
Showing 9 changed files with 40,733 additions and 17,361 deletions.
9 changes: 9 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
"jestConfig": "apps/test-project/jest.config.js",
"passWithNoTests": true
}
},
"ct": {
"builder": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/test-project/cypress.json",
"tsConfig": "apps/test-project/tsconfig.cypress.json",
"devServerTarget": "",
"testingType": "component"
}
}
}
},
Expand Down
10 changes: 10 additions & 0 deletions apps/test-project/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"pluginsFile": "./cypress/plugins/index.ts",
"supportFile": "./cypress/support/index.ts",
"component": {
"testFiles": "**/*.cy-spec.{js,ts,jsx,tsx}",
"componentFolder": "./src",
"videosFolder": "../../dist/cypress/apps/test-project/videos",
"screenshotsFolder": "../../dist/cypress/apps/test-project/screenshots"
}
}
8 changes: 8 additions & 0 deletions apps/test-project/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { startAngularDevServer } from '@jscutlery/cypress-angular';

module.exports = (on, config) => {
on('dev-server:start', (options) =>
startAngularDevServer({ options, tsConfig: 'tsconfig.cypress.json' })
);
return config;
};
1 change: 1 addition & 0 deletions apps/test-project/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@jscutlery/cypress-angular/support';
14 changes: 14 additions & 0 deletions apps/test-project/src/sample.cy-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core';
import { mount } from '@jscutlery/cypress-angular/mount';

@Component({
template: `<h1>👋 Hello!</h1>`,
})
export class GreetingsComponent {}

describe('greetings', () => {
it('should say hello', () => {
mount(GreetingsComponent);
cy.get('h1').contains('👋 Hello!');
});
});
8 changes: 8 additions & 0 deletions apps/test-project/tsconfig.cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"types": ["cypress"]
},
"include": ["cypress/support/**/*.ts", "**/*.cy-spec.ts"]
}
3 changes: 3 additions & 0 deletions apps/test-project/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
{
"path": "./tsconfig.editor.json"
},
{
"path": "./tsconfig.cypress.json"
}
],
"compilerOptions": {
Expand Down

0 comments on commit 2f18cd4

Please sign in to comment.