Skip to content

Commit f5f50c4

Browse files
Recipe: Flow with Browserify (#355)
* Recipe: Flow with Browserify * Update examples/preprocessors__flow-browserify/README.md Co-Authored-By: Jennifer Shehane <[email protected]> * Update examples/preprocessors__flow-browserify/cypress.json Co-Authored-By: Jennifer Shehane <[email protected]> * Move devDependencies to root package.json * Add new recipe to circle.yml to run tests in CI Co-authored-by: Jennifer Shehane <[email protected]>
1 parent f2c4ecd commit f5f50c4

File tree

14 files changed

+135
-0
lines changed

14 files changed

+135
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Recipe | Description
4747
[grep](./examples/preprocessors__grep) | Filter tests by name using Mocha-like `grep` syntax
4848
[Typescript with Browserify](./examples/preprocessors__typescript-browserify) | Add typescript support with browserify
4949
[Typescript with Webpack](./examples/preprocessors__typescript-webpack) | Add typescript support with webpack
50+
[Flow with Browserify](./examples/preprocessors__flow-browserify) | Add flow support with browserify
5051

5152
## Blogs
5253

circle.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ jobs:
147147
# and run only tests with name having "@admin"
148148
environment:
149149
CYPRESS_grep: '@admin'
150+
preprocessors__flow-browserify:
151+
<<: *defaults
150152
preprocessors__typescript-browserify:
151153
<<: *defaults
152154
preprocessors__typescript-webpack:
@@ -275,6 +277,9 @@ all_jobs: &all_jobs
275277
- preprocessors__grep:
276278
requires:
277279
- build
280+
- preprocessors__flow-browserify:
281+
requires:
282+
- build
278283
- preprocessors__typescript-browserify:
279284
requires:
280285
- build
@@ -368,6 +373,7 @@ all_jobs: &all_jobs
368373
- logging-in__jwt
369374
- logging-in__using-app-code
370375
- preprocessors__grep
376+
- preprocessors__flow-browserify
371377
- preprocessors__typescript-browserify
372378
- preprocessors__typescript-webpack
373379
- server-communication__bootstrapping-your-app
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[ignore]
2+
.*/node_modules
3+
4+
[include]
5+
6+
[libs]
7+
src/flow-types.js
8+
9+
[lints]
10+
11+
[options]
12+
13+
[strict]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Flow with Browserify
2+
3+
This is an example showing how to add Flow support for Cypress using Browserify.
4+
5+
Whether you use Flow in your test files or just in the source files you need to preprocess them before running the tests so Cypress runs plain JavaScript.
6+
7+
It uses [browserify](http://browserify.org/) to preprocess Flow files
8+
via [@cypress/browserify-preprocessor](https://github.com/cypress-io/cypress-browserify-preprocessor)
9+
and [@babel/preset-flow](https://github.com/babel/babel/tree/master/packages/babel-preset-flow) to transpile those files.
10+
11+
## Install
12+
`npm install --save-dev @cypress/browserify-preprocessor @babel/preset-flow`
13+
14+
See:
15+
- [cypress/plugins/index.js](cypress/plugins/index.js)
16+
- [example test](cypress/integration/spec.js)
17+
- [support/add.js](cypress/support/add.js)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"fixturesFolder": false
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @flow
2+
import { add } from '../support/add' // Flow typed file
3+
4+
declare function describe(any, Function): any
5+
declare function it(any, Function): any
6+
declare function expect(any): any
7+
8+
describe('Flow', () => {
9+
it('works', () => {
10+
// note: Flow definition
11+
const x: number = 42
12+
13+
add(1, 'a') // Flow error
14+
})
15+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const browserify = require('@cypress/browserify-preprocessor')
2+
3+
module.exports = (on, config) => {
4+
const options = browserify.defaultOptions
5+
options.browserifyOptions.transform[1][1].presets.push('@babel/preset-flow')
6+
on('file:preprocessor', browserify(options))
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @flow
2+
export const add = (a: number, b: number) => a + b
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This is will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "cypress-example-flow-browserify",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"start": "echo",
7+
"cypress:run": "../../node_modules/.bin/cypress run",
8+
"cypress:open": "../../node_modules/.bin/cypress open"
9+
}
10+
}

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"vuex": "3.1.1"
6666
},
6767
"devDependencies": {
68+
"@babel/preset-flow": "7.0.0",
6869
"@cypress/browserify-preprocessor": "2.1.1",
6970
"@cypress/snapshot": "2.1.3",
7071
"@cypress/webpack-preprocessor": "4.1.1",

0 commit comments

Comments
 (0)