Skip to content

Commit b869df0

Browse files
Enoah NetzachEnoahNetzach
authored andcommitted
Test webpack plugins
1 parent 3b609bd commit b869df0

27 files changed

+190
-37
lines changed

packages/react-scripts/templates/kitchensink/integration/initDOM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default feature => new Promise(async resolve => {
4848
const host = process.env.E2E_URL || 'http://localhost:3000'
4949
const doc = jsdom.jsdom(markup, {
5050
features : {
51-
FetchExternalResources : ['script'],
51+
FetchExternalResources : ['script', 'css'],
5252
ProcessExternalResources : ['script'],
5353
},
5454
resourceLoader,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import initDOM from './initDOM'
2+
3+
// eslint-disable-next-line no-undef
4+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
5+
6+
describe('Integration', () => {
7+
describe('Webpack plugins', () => {
8+
it('css inclusion', async () => {
9+
const doc = await initDOM('css-inclusion')
10+
11+
expect(doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, ''))
12+
.toMatch(/#feature-css-inclusion\{background:.+;color:.+}/)
13+
})
14+
15+
it('image inclusion', async () => {
16+
const doc = await initDOM('image-inclusion')
17+
18+
expect(doc.getElementById('feature-image-inclusion').src).toMatch(/^data:image\/jpeg;base64.+==$/)
19+
})
20+
21+
it('no ext inclusion', async () => {
22+
const doc = await initDOM('no-ext-inclusion')
23+
24+
expect(doc.getElementById('feature-no-ext-inclusion').textContent)
25+
.toBe('This is just a file without an extension.')
26+
})
27+
28+
it('json inclusion', async () => {
29+
const doc = await initDOM('json-inclusion')
30+
31+
expect(doc.getElementById('feature-json-inclusion').textContent).toBe('This is an abstract.')
32+
})
33+
34+
it('svg inclusion', async () => {
35+
const doc = await initDOM('svg-inclusion')
36+
37+
expect(doc.getElementById('feature-svg-inclusion').src).toMatch(/\/static\/media\/logo\..+\.svg$/)
38+
})
39+
40+
it('unknown ext inclusion', async () => {
41+
const doc = await initDOM('unknown-ext-inclusion')
42+
43+
expect(doc.getElementById('feature-unknown-ext-inclusion').textContent).toBe('Whoooo, spooky!.')
44+
})
45+
})
46+
})

packages/react-scripts/templates/kitchensink/src/App.css

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/react-scripts/templates/kitchensink/src/App.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class App extends React.Component {
3434
this.setState({ feature: require('./features/syntax/ComputedProperties').default })
3535
);
3636
break;
37+
case 'css-inclusion':
38+
require.ensure(['./features/webpack/CssInclusion'], () =>
39+
this.setState({ feature: require('./features/webpack/CssInclusion').default })
40+
);
41+
break;
3742
case 'custom-interpolation':
3843
require.ensure(['./features/syntax/CustomInterpolation'], () =>
3944
this.setState({ feature: require('./features/syntax/CustomInterpolation').default })
@@ -59,11 +64,26 @@ class App extends React.Component {
5964
this.setState({ feature: require('./features/syntax/Generators').default })
6065
);
6166
break;
67+
case 'image-inclusion':
68+
require.ensure(['./features/webpack/ImageInclusion'], () =>
69+
this.setState({ feature: require('./features/webpack/ImageInclusion').default })
70+
);
71+
break;
72+
case 'json-inclusion':
73+
require.ensure(['./features/webpack/JsonInclusion'], () =>
74+
this.setState({ feature: require('./features/webpack/JsonInclusion').default })
75+
);
76+
break;
6277
case 'node-path':
6378
require.ensure(['./features/env/NodePath'], () =>
6479
this.setState({ feature: require('./features/env/NodePath').default })
6580
);
6681
break;
82+
case 'no-ext-inclusion':
83+
require.ensure(['./features/webpack/NoExtInclusion'], () =>
84+
this.setState({ feature: require('./features/webpack/NoExtInclusion').default })
85+
);
86+
break;
6787
case 'object-destructuring':
6888
require.ensure(['./features/syntax/ObjectDestructuring'], () =>
6989
this.setState({ feature: require('./features/syntax/ObjectDestructuring').default })
@@ -94,11 +114,21 @@ class App extends React.Component {
94114
this.setState({ feature: require('./features/env/ShellEnvVariables').default })
95115
);
96116
break;
117+
case 'svg-inclusion':
118+
require.ensure(['./features/webpack/SvgInclusion'], () =>
119+
this.setState({ feature: require('./features/webpack/SvgInclusion').default })
120+
);
121+
break;
97122
case 'template-interpolation':
98123
require.ensure(['./features/syntax/TemplateInterpolation'], () =>
99124
this.setState({ feature: require('./features/syntax/TemplateInterpolation').default })
100125
);
101126
break;
127+
case 'unknown-ext-inclusion':
128+
require.ensure(['./features/webpack/UnknownExtInclusion'], () =>
129+
this.setState({ feature: require('./features/webpack/UnknownExtInclusion').default })
130+
);
131+
break;
102132
default:
103133
this.setState({ feature: null });
104134
break;

packages/react-scripts/templates/kitchensink/src/aFileWithExt.unknown

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/react-scripts/templates/kitchensink/src/aFileWithoutExt

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/react-scripts/templates/kitchensink/src/abstract.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react'
2+
import './assets/style.css'
3+
4+
export default () => (
5+
<p id="feature-css-inclusion">We love useless text.</p>
6+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import CssInclusion from './CssInclusion';
4+
5+
describe('css inclusion', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<CssInclusion />, div);
9+
});
10+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react'
2+
import tiniestCat from './assets/tiniest-cat.jpg'
3+
4+
export default () => (
5+
<img id="feature-image-inclusion" src={tiniestCat} alt="tiniest cat" />
6+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import ImageInclusion from './ImageInclusion';
4+
5+
describe('image inclusion', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<ImageInclusion />, div);
9+
});
10+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react'
2+
import { abstract } from './assets/abstract.json'
3+
4+
export default () => (
5+
<summary id="feature-json-inclusion">{abstract}</summary>
6+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import JsonInclusion from './JsonInclusion';
4+
5+
describe('JSON inclusion', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<JsonInclusion />, div);
9+
});
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import aFileWithoutExt from './assets/aFileWithoutExt'
3+
4+
const text = aFileWithoutExt.includes('base64')
5+
? atob(aFileWithoutExt.split('base64,')[1]).trim()
6+
: aFileWithoutExt
7+
8+
export default () => (
9+
<p id="feature-no-ext-inclusion">{text}.</p>
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import NoExtInclusion from './NoExtInclusion';
4+
5+
describe('no ext inclusion', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<NoExtInclusion />, div);
9+
});
10+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react'
2+
import logo from './assets/logo.svg'
3+
4+
export default () => (
5+
<img id="feature-svg-inclusion" src={logo} alt="logo" />
6+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import SvgInclusion from './SvgInclusion';
4+
5+
describe('svg inclusion', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<SvgInclusion />, div);
9+
});
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import aFileWithExtUnknown from './assets/aFileWithExt.unknown'
3+
4+
const text = aFileWithExtUnknown.includes('base64')
5+
? atob(aFileWithExtUnknown.split('base64,')[1]).trim()
6+
: aFileWithExtUnknown
7+
8+
export default () => (
9+
<p id="feature-unknown-ext-inclusion">{text}.</p>
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import UnknownExtInclusion from './UnknownExtInclusion';
4+
5+
describe('unknown ext inclusion', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<UnknownExtInclusion />, div);
9+
});
10+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Whoooo, spooky!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is just a file without an extension
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"abstract": "This is an abstract."
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#feature-css-inclusion {
2+
background: palevioletred;
3+
color: papayawhip;
4+
}

packages/react-scripts/templates/kitchensink/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './App';
4-
import './index.css';
54

65
ReactDOM.render(
76
<App />,

tasks/e2e.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ NODE_PATH=src REACT_APP_SHELL_ENV_MESSAGE=fromtheshell npm run build
153153
# Check for expected output
154154
test -e build/*.html
155155
test -e build/static/js/main.*.js
156-
test -e build/static/css/main.*.css
157-
# test -e build/static/media/*.svg # TODO uncomment this line
158-
# test -e build/favicon.ico # TODO uncomment this line
159156

160157
# Unit tests
161158
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
@@ -205,9 +202,6 @@ NODE_PATH=src REACT_APP_SHELL_ENV_MESSAGE=fromtheshell npm run build
205202
# Check for expected output
206203
test -e build/*.html
207204
test -e build/static/js/main.*.js
208-
test -e build/static/css/main.*.css
209-
# test -e build/static/media/*.svg # TODO uncomment this line
210-
# test -e build/favicon.ico # TODO uncomment this line
211205

212206
# Unit tests
213207
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \

0 commit comments

Comments
 (0)