Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Folder Name | Description
[react-scripts](examples/react-scripts) | A project using `react-scripts` with component tests in `src` folder
[react-scripts-folder](examples/react-scripts-folder) | A project using `react-scripts` with component tests in `cypress/component`
[tailwind](examples/tailwind) | Testing styles built using [Tailwind CSS](https://tailwindcss.com/)
[sass-and-ts](examples/sass-and-ts) | Example with Webpack, Sass and TypeScript
[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).
[visual-testing-with-percy](examples/visual-testing-with-percy) | [Visual testing](#visual-testing) for components using 3rd party service [Percy.io](https://percy.io/)
[visual-testing-with-happo](examples/visual-testing-with-happo) | [Visual testing](#visual-testing) for components using 3rd party service [Happo](https://happo.io/)
Expand Down Expand Up @@ -278,6 +279,8 @@ When using Node Sass styles, tell Cypress to use [the system NodeJS](https://on.
}
```

Find full example in [sass-and-ts](examples/sass-and-ts) folder.

</details>

<details id="speed">
Expand Down
16 changes: 16 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ workflows:
command: npm test
store_artifacts: true

- cypress/run:
name: Example Sass
requires:
- Install
# we need the same OS version as in install job
# because we will use native Sass dependency
executor: cypress/base-12
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
install-command: npm install
verify-command: echo 'Already verified'
no-workspace: true
working_directory: examples/sass-and-ts
command: npm test
store_artifacts: true

- cypress/run:
name: Visual Sudoku
executor: cypress/base-12
Expand Down Expand Up @@ -187,6 +202,7 @@ workflows:
requires:
- Install
- Test
- Example Sass
- Example Babel
- Example React Scripts
- Example Component Folder
Expand Down
2 changes: 2 additions & 0 deletions examples/react-scripts-folder/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('../../../../plugins/react-scripts')
module.exports = (on, config) => {
preprocessor(on, config)
Expand Down
2 changes: 2 additions & 0 deletions examples/react-scripts/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('../../../../plugins/react-scripts')
module.exports = (on, config) => {
preprocessor(on, config)
Expand Down
1 change: 1 addition & 0 deletions examples/sass-and-ts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
21 changes: 21 additions & 0 deletions examples/sass-and-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# example-sass-and-ts

> Testing components written in TypeScript with Sass imports

![Sass test](images/sass.png)

To run, need to install link first

```
npm install
```

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.

```json
{
"nodeVersion": "system"
}
```

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.
12 changes: 12 additions & 0 deletions examples/sass-and-ts/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fixturesFolder": false,
"testFiles": "**/*spec.*",
"viewportWidth": 500,
"viewportHeight": 500,
"experimentalComponentTesting": true,
"componentFolder": "src",
"nodeVersion": "system",
"env": {
"coverage": false
}
}
6 changes: 6 additions & 0 deletions examples/sass-and-ts/cypress/integration/cy-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="cypress" />
describe('integration spec', () => {
it('works', () => {
expect(1).to.equal(1)
})
})
11 changes: 11 additions & 0 deletions examples/sass-and-ts/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// load Webpack file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('cypress-react-unit-test/plugins/load-webpack')
module.exports = (on, config) => {
// point at the webpack config file at the root of the project
config.env.webpackFilename = 'webpack.config.js'
preprocessor(on, config)
// IMPORTANT to return the config object
// with the any changed environment variables
return config
}
1 change: 1 addition & 0 deletions examples/sass-and-ts/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('cypress-react-unit-test/support')
Binary file added examples/sass-and-ts/images/sass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions examples/sass-and-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "example-sass-and-ts",
"description": "Testing components written in TypeScript with Sass imports",
"private": true,
"scripts": {
"test": "../../node_modules/.bin/cypress run",
"cy:open": "../../node_modules/.bin/cypress open"
},
"devDependencies": {
"cypress-react-unit-test": "file:../.."
}
}
10 changes: 10 additions & 0 deletions examples/sass-and-ts/src/App.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { mount } from 'cypress-react-unit-test'
import App from './App.tsx'

describe('Sass and TS App', () => {
it('has style', () => {
mount(<App />)
cy.get('.App').should('have.css', 'text-align', 'center')
})
})
12 changes: 12 additions & 0 deletions examples/sass-and-ts/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'

import './styles.scss'

export default function App() {
return (
<div className="App">
<h1>Hello React</h1>
<h2>This TS component imports Scss styles</h2>
</div>
)
}
4 changes: 4 additions & 0 deletions examples/sass-and-ts/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.App {
font-family: sans-serif;
text-align: center;
}
31 changes: 31 additions & 0 deletions examples/sass-and-ts/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path')
module.exports = {
resolve: {
// for this example, let's point 'cypress-react-unit-test' at the root
alias: {
'cypress-react-unit-test': path.resolve('../..'),
},
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties'],
},
},
{
test: /\.scss$/i,
use: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
},
],
},
],
},
}
2 changes: 2 additions & 0 deletions examples/tailwind/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('../../../../plugins/react-scripts')
module.exports = (on, config) => {
preprocessor(on, config)
Expand Down
1 change: 1 addition & 0 deletions examples/using-babel/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// let's bundle spec files and the components they include using
// the same bundling settings as the project by loading .babelrc
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('cypress-react-unit-test/plugins/babelrc')
module.exports = (on, config) => {
preprocessor(on, config)
Expand Down
2 changes: 2 additions & 0 deletions examples/visual-sudoku/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('../../../../plugins/react-scripts')
const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('../../../../plugins/react-scripts')
module.exports = (on, config) => {
preprocessor(on, config)
Expand Down
2 changes: 2 additions & 0 deletions examples/visual-testing-with-happo/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const preprocessor = require('../../../../plugins/react-scripts')
const happoTask = require('happo-cypress/task')

Expand Down
2 changes: 2 additions & 0 deletions examples/visual-testing-with-percy/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// load file preprocessor that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
const percyHealthCheck = require('@percy/cypress/task')
const preprocessor = require('../../../../plugins/react-scripts')
module.exports = (on, config) => {
Expand Down
Loading