Skip to content

Commit 35b11b3

Browse files
committed
Fixing tests by allowing for more [hash:8] wildcards
1 parent 8b77e37 commit 35b11b3

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

test/functional.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ describe('Functional tests using webpack', function() {
429429
]);
430430

431431
webpackAssert.assertOutputFileContains(
432-
'styles.79943add.css',
432+
'styles.[hash:8].css',
433433
'font-size: 50px;'
434434
);
435435
webpackAssert.assertManifestPathDoesNotExist(
436436
'styles.js'
437437
);
438438
webpackAssert.assertManifestPath(
439439
'styles.css',
440-
'/styles.79943add.css'
440+
'/styles.[hash:8].css'
441441
);
442442

443443
done();
@@ -468,7 +468,7 @@ describe('Functional tests using webpack', function() {
468468
);
469469
webpackAssert.assertManifestPath(
470470
'styles.css',
471-
'/styles.css?79943addbc894efe'
471+
'/styles.css?[hash:16]'
472472
);
473473

474474
done();
@@ -537,7 +537,7 @@ describe('Functional tests using webpack', function() {
537537
]);
538538

539539
webpackAssert.assertOutputFileContains(
540-
'bg.2eff0999.css',
540+
'bg.[hash:8].css',
541541
'/build/images/symfony_logo.91beba37.png'
542542
);
543543

@@ -1915,7 +1915,7 @@ module.exports = {
19151915
});
19161916
});
19171917

1918-
it('Symfony - Stimulus standard app is built correctly', function (done) {
1918+
it('Symfony - Stimulus standard app is built correctly', function(done) {
19191919
const appDir = testSetup.createTestAppDir();
19201920

19211921
const version = packageHelper.getPackageVersion('@symfony/stimulus-bridge');

test/helpers/assert.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ const readOutputFile = function(webpackConfig, filePath) {
3131
return fs.readFileSync(fullPath, 'utf8');
3232
};
3333

34+
const getMatchedFilename = function(targetDirectory, filenameRegex) {
35+
const actualFiles = fs.readdirSync(targetDirectory);
36+
let foundFile = false;
37+
actualFiles.forEach((actualFile) => {
38+
// filter out directories
39+
if (fs.statSync(path.join(targetDirectory, actualFile)).isDirectory()) {
40+
return;
41+
}
42+
43+
if (actualFile.match(filenameRegex)) {
44+
foundFile = actualFile;
45+
}
46+
});
47+
48+
return foundFile;
49+
};
50+
3451
/**
3552
* Returns a regex to use to match this filename
3653
*
@@ -61,12 +78,17 @@ class Assert {
6178
}
6279

6380
assertOutputFileContains(filePath, expectedContents) {
64-
const fullPath = path.join(this.webpackConfig.outputPath, filePath);
81+
const actualFilename = getMatchedFilename(
82+
this.webpackConfig.outputPath,
83+
convertFilenameToMatcher(filePath)
84+
);
6585

66-
if (!fs.existsSync(fullPath)) {
86+
if (false === actualFilename) {
6787
throw new Error(`Output file "${filePath}" does not exist.`);
6888
}
6989

90+
const fullPath = path.join(this.webpackConfig.outputPath, actualFilename);
91+
7092
const actualContents = fs.readFileSync(fullPath, 'utf8');
7193
if (!actualContents.includes(expectedContents)) {
7294
throw new Error(`Expected contents "${expectedContents}" not found in file ${fullPath}`);

0 commit comments

Comments
 (0)