Skip to content

Commit db980b4

Browse files
committed
Looking up paths in the manifest file in the functional tests
This makes things *just* a little bit more realistic
1 parent 1a3300e commit db980b4

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lib/test/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function requestTestPage(webRootDir, scriptSrcs, callback) {
158158

159159
const browser = new Browser();
160160
browser.on('error', function(error) {
161-
throw new Error(error);
161+
throw new Error(`Error when running the browser: ${error}`);
162162
});
163163
browser.visit('http://127.0.0.1:8080/testing.html', () => {
164164
stopAllServers();

test/functional.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ function createWebpackConfig(outputDirName = '', command, argv = {}) {
2525
);
2626
}
2727

28+
function convertToManifestPath(assetSrc, webpackConfig) {
29+
const manifestData = JSON.parse(
30+
fs.readFileSync(path.join(webpackConfig.outputPath, 'manifest.json'), 'utf8')
31+
);
32+
33+
if (typeof manifestData[assetSrc] === 'undefined') {
34+
throw new Error(`Path ${assetSrc} not found in manifest!`);
35+
}
36+
37+
return manifestData[assetSrc];
38+
}
39+
2840
describe('Functional tests using webpack', function() {
2941
// being functional tests, these can take quite long
3042
this.timeout(5000);
@@ -101,7 +113,10 @@ describe('Functional tests using webpack', function() {
101113

102114
testSetup.requestTestPage(
103115
path.join(config.getContext(), 'public'),
104-
['/assets/main.js'],
116+
[
117+
// purposely load this NOT from the CDN
118+
'assets/main.js'
119+
],
105120
(browser) => {
106121
webpackAssert.assertResourcesLoadedCorrectly(browser, [
107122
'0.js',
@@ -147,15 +162,13 @@ describe('Functional tests using webpack', function() {
147162

148163
testSetup.requestTestPage(
149164
path.join(config.getContext(), 'public'),
150-
['/assets/main.js'],
165+
[
166+
convertToManifestPath('assets/main.js', config)
167+
],
151168
(browser) => {
152169
webpackAssert.assertResourcesLoadedCorrectly(browser, [
153170
'0.js',
154-
// guarantee that we assert that main.js is loaded from the
155-
// main server, as it's simply a script tag to main.js on the page
156-
// we did this to check that the internally-loaded assets
157-
// use the CDN, even if the entry point does not
158-
'http://127.0.0.1:8080/assets/main.js'
171+
'main.js'
159172
]);
160173

161174
done();
@@ -179,7 +192,9 @@ describe('Functional tests using webpack', function() {
179192
testSetup.requestTestPage(
180193
// the webroot will not include the /subdirectory/build part
181194
path.join(config.getContext(), ''),
182-
['/subdirectory/build/main.js'],
195+
[
196+
convertToManifestPath('build/main.js', config)
197+
],
183198
(browser) => {
184199
webpackAssert.assertResourcesLoadedCorrectly(browser, [
185200
'http://127.0.0.1:8080/subdirectory/build/0.js',

0 commit comments

Comments
 (0)