Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes webpack-manifest-plugin issue #3

Closed
wants to merge 20 commits into from
2 changes: 2 additions & 0 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ module.exports = {
.replace(/\\/g, '/'),
},
optimization: {
// webpack-manifest-plugin currently does not play well with ConcatenatedModule
concatenateModules: false,
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
Expand Down
19 changes: 6 additions & 13 deletions packages/react-scripts/fixtures/kitchensink/integration/initDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const path = require('path');
const { expect } = require('chai');

let getMarkup;
let resourceLoader;
export let resourceLoader;

if (process.env.E2E_FILE) {
const file = path.isAbsolute(process.env.E2E_FILE)
Expand Down Expand Up @@ -47,25 +47,18 @@ if (process.env.E2E_FILE) {

resourceLoader = (resource, callback) => resource.defaultFetch(callback);
} else {
it.only(
'can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)',
() => {
expect(
new Error("This isn't the error you are looking for.")
).to.be.undefined();
}
);
it.only('can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)', () => {
expect(
new Error("This isn't the error you are looking for.")
).to.be.undefined();
});
}

export default feature =>
new Promise(async resolve => {
const markup = await getMarkup();
const host = process.env.E2E_URL || 'http://www.example.org/spa:3000';
const doc = jsdom.jsdom(markup, {
features: {
FetchExternalResources: ['script', 'css'],
ProcessExternalResources: ['script'],
},
created: (_, win) =>
win.addEventListener('ReactFeatureDidMount', () => resolve(doc), true),
deferClose: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,68 @@
*/

import { expect } from 'chai';
import initDOM from './initDOM';
import initDOM, { resourceLoader } from './initDOM';
import url from 'url';

const matchCSS = (doc, regexes) => {
if (process.env.E2E_FILE) {
const elements = doc.getElementsByTagName('link');
let href = "";
for (const elem of elements) {
if (elem.rel === 'stylesheet') {
href = elem.href;
}
}
resourceLoader(
{ url: url.parse(href) },
(_, textContent) => {
for (const regex of regexes) {
expect(textContent).to.match(regex);
}
}
);

} else {
for (let i = 0; i < regexes.length; ++i) {
expect(doc.getElementsByTagName('style')[i].textContent.replace(/\s/g, '')).to.match(regexes[i]);
}
}
}

describe('Integration', () => {
describe('Webpack plugins', () => {
it('css inclusion', async () => {
const doc = await initDOM('css-inclusion');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(/html\{/);
expect(
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
).to.match(/#feature-css-inclusion\{background:.+;color:.+}/);
matchCSS(doc, [/html\{/, /#feature-css-inclusion\{background:.+;color:.+}/]);
});

it('css modules inclusion', async () => {
const doc = await initDOM('css-modules-inclusion');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(/.+style_cssModulesInclusion__.+\{background:.+;color:.+}/);
expect(
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
).to.match(
/.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/
);
matchCSS(doc, [/.+style_cssModulesInclusion__.+\{background:.+;color:.+}/,
/.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/]);
});

it('scss inclusion', async () => {
const doc = await initDOM('scss-inclusion');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(/#feature-scss-inclusion\{background:.+;color:.+}/);
matchCSS(doc, [/#feature-scss-inclusion\{background:.+;color:.+}/]);
});

it('scss modules inclusion', async () => {
const doc = await initDOM('scss-modules-inclusion');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(
/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/
);
expect(
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
).to.match(
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/
);
matchCSS(doc, [/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/,
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/]);

});

it('sass inclusion', async () => {
const doc = await initDOM('sass-inclusion');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(/#feature-sass-inclusion\{background:.+;color:.+}/);
matchCSS(doc, [/#feature-sass-inclusion\{background:.+;color:.+}/]);
});

it('sass modules inclusion', async () => {
const doc = await initDOM('sass-modules-inclusion');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(
/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/
);
expect(
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
).to.match(
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/
);
matchCSS(doc, [/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/,
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/]);
});

it('graphql files inclusion', async () => {
Expand Down Expand Up @@ -124,7 +114,6 @@ describe('Integration', () => {

it('svg inclusion', async () => {
const doc = await initDOM('svg-inclusion');

expect(doc.getElementById('feature-svg-inclusion').src).to.match(
/\/static\/media\/logo\..+\.svg$/
);
Expand All @@ -140,10 +129,7 @@ describe('Integration', () => {

it('svg in css', async () => {
const doc = await initDOM('svg-in-css');

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(/\/static\/media\/logo\..+\.svg/);
matchCSS(doc, [/\/static\/media\/logo\..+\.svg/]);
});

it('unknown ext inclusion', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-scripts/scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ module.exports = (resolve, rootDir, srcRoots) => {
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$',
'^.+\\.module\\.css$',
'^.+\\.module\\.(css|sass|scss)$',
],
moduleNameMapper: {
'^react-native$': 'react-native-web',
'^.+\\.module\\.css$': 'identity-obj-proxy',
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
},
moduleFileExtensions: [
'web.js',
Expand Down
2 changes: 1 addition & 1 deletion tasks/e2e-installs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ yarn

# Start local registry
tmp_registry_log=`mktemp`
nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
nohup npx verdaccio@2.7.2 -c tasks/verdaccio.yaml &>$tmp_registry_log &
# Wait for `verdaccio` to boot
grep -q 'http address' <(tail -f $tmp_registry_log)

Expand Down