Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 4ac914f

Browse files
authored
Add sass example (#248)
1 parent 149a895 commit 4ac914f

File tree

24 files changed

+826
-2
lines changed

24 files changed

+826
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Folder Name | Description
161161
[react-scripts](examples/react-scripts) | A project using `react-scripts` with component tests in `src` folder
162162
[react-scripts-folder](examples/react-scripts-folder) | A project using `react-scripts` with component tests in `cypress/component`
163163
[tailwind](examples/tailwind) | Testing styles built using [Tailwind CSS](https://tailwindcss.com/)
164+
[sass-and-ts](examples/sass-and-ts) | Example with Webpack, Sass and TypeScript
164165
[visual-sudoku](examples/visual-sudoku) | [Visual testing](#visual-testing) for components using open source plugin [cypress-image-snapshot](https://github.com/palmerhq/cypress-image-snapshot). For larger example with an hour long list of explanation videos, see [bahmutov/sudoku](https://github.com/bahmutov/sudoku).
165166
[visual-testing-with-percy](examples/visual-testing-with-percy) | [Visual testing](#visual-testing) for components using 3rd party service [Percy.io](https://percy.io/)
166167
[visual-testing-with-happo](examples/visual-testing-with-happo) | [Visual testing](#visual-testing) for components using 3rd party service [Happo](https://happo.io/)
@@ -278,6 +279,8 @@ When using Node Sass styles, tell Cypress to use [the system NodeJS](https://on.
278279
}
279280
```
280281

282+
Find full example in [sass-and-ts](examples/sass-and-ts) folder.
283+
281284
</details>
282285

283286
<details id="speed">

circle.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ workflows:
9595
command: npm test
9696
store_artifacts: true
9797

98+
- cypress/run:
99+
name: Example Sass
100+
requires:
101+
- Install
102+
# we need the same OS version as in install job
103+
# because we will use native Sass dependency
104+
executor: cypress/base-12
105+
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
106+
install-command: npm install
107+
verify-command: echo 'Already verified'
108+
no-workspace: true
109+
working_directory: examples/sass-and-ts
110+
command: npm test
111+
store_artifacts: true
112+
98113
- cypress/run:
99114
name: Visual Sudoku
100115
executor: cypress/base-12
@@ -187,6 +202,7 @@ workflows:
187202
requires:
188203
- Install
189204
- Test
205+
- Example Sass
190206
- Example Babel
191207
- Example React Scripts
192208
- Example Component Folder

examples/react-scripts-folder/cypress/plugins/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// load file preprocessor that comes with this plugin
2+
// https://github.com/bahmutov/cypress-react-unit-test#install
13
const preprocessor = require('../../../../plugins/react-scripts')
24
module.exports = (on, config) => {
35
preprocessor(on, config)

examples/react-scripts/cypress/plugins/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// load file preprocessor that comes with this plugin
2+
// https://github.com/bahmutov/cypress-react-unit-test#install
13
const preprocessor = require('../../../../plugins/react-scripts')
24
module.exports = (on, config) => {
35
preprocessor(on, config)

examples/sass-and-ts/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/sass-and-ts/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# example-sass-and-ts
2+
3+
> Testing components written in TypeScript with Sass imports
4+
5+
![Sass test](images/sass.png)
6+
7+
To run, need to install link first
8+
9+
```
10+
npm install
11+
```
12+
13+
Note that Node Sass is a binary dependency, thus we need to run it using the same system version of Node as we installed. See [cypress.json](cypress.json) file.
14+
15+
```json
16+
{
17+
"nodeVersion": "system"
18+
}
19+
```
20+
21+
To bundle code using the same [webpack.config.js](webpack.config.js) file, we point at it from [cypress/plugins/index.js](cypress/plugins/index.js) file.

examples/sass-and-ts/cypress.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"fixturesFolder": false,
3+
"testFiles": "**/*spec.*",
4+
"viewportWidth": 500,
5+
"viewportHeight": 500,
6+
"experimentalComponentTesting": true,
7+
"componentFolder": "src",
8+
"nodeVersion": "system",
9+
"env": {
10+
"coverage": false
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference types="cypress" />
2+
describe('integration spec', () => {
3+
it('works', () => {
4+
expect(1).to.equal(1)
5+
})
6+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// load Webpack file preprocessor that comes with this plugin
2+
// https://github.com/bahmutov/cypress-react-unit-test#install
3+
const preprocessor = require('cypress-react-unit-test/plugins/load-webpack')
4+
module.exports = (on, config) => {
5+
// point at the webpack config file at the root of the project
6+
config.env.webpackFilename = 'webpack.config.js'
7+
preprocessor(on, config)
8+
// IMPORTANT to return the config object
9+
// with the any changed environment variables
10+
return config
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('cypress-react-unit-test/support')

0 commit comments

Comments
 (0)