Skip to content

Commit

Permalink
Try to fix Windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 1, 2022
1 parent 5cf0d58 commit e2f6395
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions test/chunking-form/samples/render-chunk-transform/_config.js
@@ -1,5 +1,6 @@
const assert = require('assert');
const path = require('path');
const { replaceDirInStringifiedObject } = require('../../../utils');

module.exports = {
description: 'replaces hashes when mutating chunk info in renderChunk',
Expand All @@ -20,9 +21,10 @@ module.exports = {
},
generateBundle(options, bundle) {
const sanitizedBundle = JSON.parse(
JSON.stringify(bundle)
.replace(/(entry-\w+)-\w+\.js/g, (match, name) => `${name}.js`)
.replace(new RegExp(__dirname, 'g'), '**')
replaceDirInStringifiedObject(bundle, __dirname).replace(
/(entry-\w+)-\w+\.js/g,
(match, name) => `${name}.js`
)
);
for (const fileName of Object.keys(sanitizedBundle)) {
delete sanitizedBundle[fileName].code;
Expand Down
6 changes: 2 additions & 4 deletions test/chunking-form/samples/render-chunk/_config.js
@@ -1,4 +1,5 @@
const assert = require('assert');
const { replaceDirInStringifiedObject } = require('../../../utils');

module.exports = {
description:
Expand All @@ -15,10 +16,7 @@ module.exports = {
assert.strictEqual(chunks[chunk.fileName], chunk);
return (
code +
`\nconsole.log(${JSON.stringify(chunk, null, 2).replace(
new RegExp(__dirname, 'g'),
'**'
)});` +
`\nconsole.log(${replaceDirInStringifiedObject(chunk, __dirname)});` +
`\nconsole.log('all chunks', ${JSON.stringify(Object.keys(chunks))})` +
`\nconsole.log('referenced asset in renderChunk', '${this.getFileName(
this.emitFile({ type: 'asset', name: 'test', source: 'test' })
Expand Down
4 changes: 2 additions & 2 deletions test/form/samples/addon-functions/_config.js
@@ -1,8 +1,8 @@
const assert = require('assert');
const replaceDirname = new RegExp(__dirname, 'g');
const { replaceDirInStringifiedObject } = require('../../../utils');
const assertChunkData = chunk =>
assert.strictEqual(
JSON.stringify({ ...chunk, fileName: undefined }, null, 2).replace(replaceDirname, '**'),
replaceDirInStringifiedObject({ ...chunk, fileName: undefined }, __dirname),
'{\n' +
' "exports": [],\n' +
' "facadeModuleId": "**/main.js",\n' +
Expand Down
14 changes: 11 additions & 3 deletions test/utils.js
Expand Up @@ -272,7 +272,7 @@ exports.writeAndSync = function writeAndSync(filePath, contents) {
// Sometimes, watchers on MacOS do not seem to fire. In those cases, it helps
// to write the same content again. This function returns a callback to stop
// further updates.
function writeAndRetry(filePath, contents) {
exports.writeAndRetry = function writeAndRetry(filePath, contents) {
let retries = 0;
let updateRetryTimeout;

Expand All @@ -287,6 +287,14 @@ function writeAndRetry(filePath, contents) {

writeFile();
return () => clearTimeout(updateRetryTimeout);
}
};

exports.writeAndRetry = writeAndRetry;
exports.replaceDirInStringifiedObject = function replaceDirInStringifiedObject(object, replaced) {
return JSON.stringify(object, null, 2).replace(
new RegExp(
JSON.stringify(JSON.stringify(replaced).slice(1, -1)).slice(1, -1) + '[/\\]?\\?',
'g'
),
'**/'
);
};

0 comments on commit e2f6395

Please sign in to comment.