Skip to content

Commit 92a544a

Browse files
committed
add webpack example
1 parent 37f0e81 commit 92a544a

File tree

11 files changed

+216
-1
lines changed

11 files changed

+216
-1
lines changed

examples/use-webpack/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["istanbul"]
3+
}

examples/use-webpack/README.md

Whitespace-only changes.

examples/use-webpack/cypress.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"baseUrl": "http://localhost:5000"
2+
"baseUrl": "http://localhost:5000",
3+
"supportFile": "../../support",
4+
"fixturesFolder": false
35
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
import { add } from '../../src/calc'
3+
4+
describe('Webpack example', () => {
5+
it('loads', () => {
6+
cy.visit('/')
7+
cy.get('#user-input').type('Hello{enter}')
8+
cy.contains('olleH').should('be.visible')
9+
})
10+
11+
it('has add function', () => {
12+
// test "add" via this unit test
13+
expect(add(2, 3)).to.equal(5)
14+
})
15+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference types="cypress" />
2+
const webpack = require('@cypress/webpack-preprocessor')
3+
4+
/**
5+
* @type {Cypress.PluginConfig}
6+
*/
7+
module.exports = (on, config) => {
8+
const options = {
9+
// use the same Webpack options to bundle spec files as your app does "normally"
10+
// which should instrument the spec files in this project
11+
webpackOptions: require('../../webpack.config'),
12+
watchOptions: {}
13+
}
14+
on('file:preprocessor', webpack(options))
15+
16+
require('../../../../task')(on, config)
17+
return config
18+
}

examples/use-webpack/dist/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
</head>
66
<body>
77
<p>Webpack page</p>
8+
<input id="user-input" type="text" />
9+
<div id="reversed"></div>
810
<script src="main.js"></script>
911
</body>
1012
</html>

examples/use-webpack/src/calc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const add = (a, b) => {
2+
return a + b
3+
}
4+
5+
export const reverse = s => {
6+
return s
7+
.split('')
8+
.reverse()
9+
.join('')
10+
}

examples/use-webpack/src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { reverse } from './calc'
2+
3+
document.getElementById('user-input').addEventListener('change', e => {
4+
const s = e.target.value
5+
const reversed = reverse(s)
6+
document.getElementById('reversed').innerText = reversed
7+
})

examples/use-webpack/webpack.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,21 @@ module.exports = {
88
output: {
99
filename: 'main.js',
1010
path: path.resolve(__dirname, 'dist')
11+
},
12+
module: {
13+
rules: [
14+
{
15+
// when bundling application's own source code
16+
// transpile using Babel which uses .babelrc file
17+
// and instruments code using babel-plugin-istanbul
18+
test: /\.js/,
19+
exclude: /(node_modules|bower_components)/,
20+
use: [
21+
{
22+
loader: 'babel-loader'
23+
}
24+
]
25+
}
26+
]
1127
}
1228
}

package-lock.json

Lines changed: 140 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
},
5656
"devDependencies": {
5757
"@babel/core": "7.9.0",
58+
"@cypress/webpack-preprocessor": "5.1.2",
59+
"babel-loader": "8.1.0",
5860
"babel-plugin-istanbul": "6.0.0",
5961
"check-code-coverage": "1.0.1",
6062
"cypress": "4.4.0",

0 commit comments

Comments
 (0)