This repository was archived by the owner on Mar 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +286
-16
lines changed Expand file tree Collapse file tree 10 files changed +286
-16
lines changed Original file line number Diff line number Diff line change 1
1
{
2
+ "sourceType" : " unambiguous" ,
2
3
"presets" : [
3
4
" @babel/preset-env" ,
4
5
" @babel/preset-react" ,
5
- {
6
- "plugins" : [" @babel/plugin-proposal-class-properties" ]
7
- },
6
+ // {
7
+ // "plugins": ["@babel/plugin-proposal-class-properties"]
8
+ // },
8
9
" @emotion/babel-preset-css-prop"
9
10
],
11
+ "plugins" : [" @babel/plugin-proposal-class-properties" ],
10
12
"env" : {
11
13
// TODO switch this to "development" name
12
- "test " : {
14
+ "development " : {
13
15
"plugins" : [
14
16
// during Cypress tests we want to instrument source code
15
17
// to get code coverage from tests
16
- " babel-plugin-istanbul" ,
18
+ // "babel-plugin-istanbul"
17
19
// we also want to export ES6 modules as objects
18
20
// to allow mocking named imports
19
21
[
20
22
" @babel/plugin-transform-modules-commonjs" ,
21
23
{
24
+ "allowCommonJSExports" : true ,
22
25
"loose" : true
23
26
}
24
27
]
Original file line number Diff line number Diff line change
1
+ /// <reference types="cypress" />
2
+ import React from 'react'
3
+ import { getRandomNumber } from './calc'
4
+
5
+ const Component = ( ) => {
6
+ const n = getRandomNumber ( )
7
+ return < div className = "random" > { n } </ div >
8
+ }
9
+
10
+ export default Component
Original file line number Diff line number Diff line change
1
+ /// <reference types="cypress" />
2
+ import React from 'react'
3
+ import { mount } from 'cypress-react-unit-test'
4
+ import Component from './Component.jsx'
5
+ import * as calc from './calc'
6
+
7
+ describe ( 'Component' , ( ) => {
8
+ it ( 'mocks call from the component' , ( ) => {
9
+ cy . stub ( calc , 'getRandomNumber' )
10
+ . as ( 'lucky' )
11
+ . returns ( 777 )
12
+ mount ( < Component /> )
13
+ } )
14
+ } )
Original file line number Diff line number Diff line change
1
+ /// <reference types="cypress" />
2
+ const React = require ( 'react' )
3
+ const { getRandomNumber } = require ( './calc' )
4
+
5
+ const Component = ( ) => {
6
+ const n = getRandomNumber ( )
7
+ return < div className = "random" > { n } </ div >
8
+ }
9
+
10
+ module . exports = Component
Original file line number Diff line number Diff line change
1
+ /// <reference types="cypress" />
2
+ const React = require ( 'react' )
3
+ const { mount } = require ( 'cypress-react-unit-test' )
4
+ const Component = require ( './ComponentReq.jsx' )
5
+ const calc = require ( './calc' )
6
+
7
+ describe ( 'Component' , ( ) => {
8
+ it ( 'mocks call from the component' , ( ) => {
9
+ cy . stub ( calc , 'getRandomNumber' )
10
+ . as ( 'lucky' )
11
+ . returns ( 777 )
12
+ mount ( < Component /> )
13
+ } )
14
+ } )
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import * as calc from './calc'
6
6
7
7
describe ( 'Mocking' , ( ) => {
8
8
// https://github.com/bahmutov/cypress-react-unit-test/issues/266
9
- it . skip ( 'mocks import used by the Post' , ( ) => {
9
+ it ( 'mocks import used by the Post' , ( ) => {
10
10
cy . stub ( calc , 'getRandomNumber' )
11
11
. as ( 'lucky' )
12
12
. returns ( 777 )
Original file line number Diff line number Diff line change
1
+ import * as calc from './calc'
2
+
3
+ // checking mocked value if there is no React involved
4
+ describe ( 'plain' , ( ) => {
5
+ it ( 'mocks es6 import' , ( ) => {
6
+ cy . stub ( calc , 'getRandomNumber' )
7
+ . as ( 'lucky' )
8
+ . returns ( 777 )
9
+
10
+ cy . then ( ( ) => {
11
+ return calc . getRandomNumber ( )
12
+ } ) . should ( 'equal' , 777 )
13
+ } )
14
+ } )
Original file line number Diff line number Diff line change 121
121
"url" : " https://github.com/bahmutov/cypress-react-unit-test.git"
122
122
},
123
123
"dependencies" : {
124
- "@babel/plugin-transform-modules-commonjs" : " 7.7.5 " ,
124
+ "@babel/plugin-transform-modules-commonjs" : " 7.10.1 " ,
125
125
"@cypress/code-coverage" : " 3.8.1" ,
126
126
"@cypress/webpack-preprocessor" : " 5.4.1" ,
127
127
"babel-plugin-istanbul" : " 6.0.0" ,
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ module.exports = config => {
59
59
60
60
const wpPreprocessorOptions = webpackPreprocessor . defaultOptions
61
61
enableBabelrc ( wpPreprocessorOptions . webpackOptions )
62
+ debug ( 'webpack options %o' , wpPreprocessorOptions . webpackOptions )
62
63
63
64
addImageRedirect ( wpPreprocessorOptions . webpackOptions )
64
65
You can’t perform that action at this time.
0 commit comments