Skip to content

Commit

Permalink
Make Jest snapshots stable (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 committed Jul 6, 2023
1 parent 9620c75 commit c7b6e02
Show file tree
Hide file tree
Showing 37 changed files with 244 additions and 143 deletions.
9 changes: 5 additions & 4 deletions fixtures/braid-design-system/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { ListExternalsWebpackPlugin } = require('@sku-private/test-utils');
const {
ListExternalsWebpackPlugin,
makeStableHashes,
} = require('@sku-private/test-utils');

module.exports = {
sites: [
Expand All @@ -13,9 +16,7 @@ module.exports = {
config.plugins.push(new ListExternalsWebpackPlugin());
}

// Addresses an issue with this specific test suite where module IDs
// were different between local dev and CI
config.optimization.moduleIds = 'named';
makeStableHashes(config);

return config;
},
Expand Down
1 change: 1 addition & 0 deletions fixtures/custom-src-paths/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"dedent": "^0.7.0",
"sku": "workspace:*"
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/custom-src-paths/sku.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { SkuConfig } from 'sku';
// @ts-ignore no types
import { makeStableHashes } from '@sku-private/test-utils';

export default {
srcPaths: ['lib', 'another-folder'],
clientEntry: 'lib/client.js',
renderEntry: 'lib/render.js',
port: 8201,
publicPath: '/some-static-place',
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
} satisfies SkuConfig;
1 change: 1 addition & 0 deletions fixtures/library-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@sku-fixtures/library-build",
"private": true,
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"dedent": "^0.7.0",
"sku": "workspace:*"
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/library-build/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const { makeStableHashes } = require('@sku-private/test-utils');

module.exports = {
libraryEntry: 'src/library.js',
renderEntry: 'src/render.js',
libraryName: 'MyLibrary',
port: 8085,
persistentCache: false,
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
};
1 change: 1 addition & 0 deletions fixtures/library-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@sku-fixtures/library-file",
"private": true,
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"dedent": "^0.7.0",
"sku": "workspace:*"
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/library-file/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const { makeStableHashes } = require('@sku-private/test-utils');

module.exports = {
libraryEntry: 'src/library.js',
renderEntry: 'src/render.js',
libraryName: 'MyLibrary',
libraryFile: 'my-library',
port: 8086,
persistentCache: false,
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
};
1 change: 1 addition & 0 deletions fixtures/multiple-routes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"react-router-dom": "^5.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"@testing-library/react": "^14.0.0",
"dedent": "^0.7.0",
"sku": "workspace:*"
Expand Down
3 changes: 3 additions & 0 deletions fixtures/multiple-routes/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { makeStableHashes } from '@sku-private/test-utils';

export default {
sites: [
{
Expand Down Expand Up @@ -25,5 +27,6 @@ export default {
'https://error-tracking.com',
'https://fb-tracking.com',
],
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
skipPackageCompatibilityCompilation: ['react-router-dom'],
};
1 change: 1 addition & 0 deletions fixtures/public-path/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"dedent": "^0.7.0",
"sku": "workspace:*"
}
Expand Down
5 changes: 4 additions & 1 deletion fixtures/public-path/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
import { makeStableHashes } from '@sku-private/test-utils';

export default {
publicPath: '/static',
target: 'dist/static',
port: 4001,
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
};
1 change: 1 addition & 0 deletions fixtures/react-css-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"dedent": "^0.7.0",
"sku": "workspace:*"
}
Expand Down
5 changes: 4 additions & 1 deletion fixtures/react-css-modules/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
import { makeStableHashes } from '@sku-private/test-utils';

export default {
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
setupTests: 'src/setupTests.js',
};
7 changes: 6 additions & 1 deletion fixtures/sku-with-https/sku-server.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { ListExternalsWebpackPlugin } = require('@sku-private/test-utils');
const {
ListExternalsWebpackPlugin,
makeStableHashes,
} = require('@sku-private/test-utils');

module.exports = {
clientEntry: 'src/serverClient.js',
Expand All @@ -13,6 +16,8 @@ module.exports = {
config.plugins.push(new ListExternalsWebpackPlugin());
}

makeStableHashes(config);

return config;
},
};
7 changes: 6 additions & 1 deletion fixtures/sku-with-https/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { ListExternalsWebpackPlugin } = require('@sku-private/test-utils');
const {
ListExternalsWebpackPlugin,
makeStableHashes,
} = require('@sku-private/test-utils');

module.exports = {
port: 9843,
Expand All @@ -11,6 +14,8 @@ module.exports = {
config.plugins.push(new ListExternalsWebpackPlugin());
}

makeStableHashes(config);

return config;
},
};
1 change: 1 addition & 0 deletions fixtures/source-maps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"dedent": "^0.7.0",
"sku": "workspace:*"
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/source-maps/sku.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { makeStableHashes } = require('@sku-private/test-utils');

module.exports = {
publicPath: '/static/source-maps',
port: 8303,
target: 'dist',
sourceMapsProd: true,
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
};
1 change: 1 addition & 0 deletions fixtures/ssr-hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"sku": "workspace:*"
}
}
3 changes: 3 additions & 0 deletions fixtures/ssr-hello-world/sku-build.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { makeStableHashes } = require('@sku-private/test-utils');

module.exports = {
publicPath: 'http://localhost:4000',
port: 8000,
Expand All @@ -6,4 +8,5 @@ module.exports = {
public: 'assets',
cspEnabled: true,
cspExtraScriptSrcHosts: ['https://some-cdn.com'],
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
};
3 changes: 3 additions & 0 deletions fixtures/ssr-hello-world/sku-start.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { makeStableHashes } = require('@sku-private/test-utils');

module.exports = {
publicPath: 'http://localhost:4000',
port: 8100,
Expand All @@ -6,4 +8,5 @@ module.exports = {
devServerMiddleware: './dev-middleware.js',
cspEnabled: true,
cspExtraScriptSrcHosts: ['https://some-cdn.com'],
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
};
1 change: 1 addition & 0 deletions fixtures/typescript-css-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@sku-private/test-utils": "workspace:*",
"@types/react": "^18.2.3",
"@types/react-dom": "^18.2.3",
"dedent": "^0.7.0",
Expand Down
3 changes: 3 additions & 0 deletions fixtures/typescript-css-modules/sku-ssr.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { SkuConfig } from 'sku';
// @ts-ignore no types
import { makeStableHashes } from '@sku-private/test-utils';

export default {
clientEntry: 'src/client-ssr.tsx',
Expand All @@ -8,4 +10,5 @@ export default {
// Required for test to serve client assets correctly
publicPath: 'http://localhost:4003/',
target: 'dist-ssr',
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
} satisfies SkuConfig;
3 changes: 3 additions & 0 deletions fixtures/typescript-css-modules/sku.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { SkuConfig } from 'sku';
// @ts-ignore no types
import { makeStableHashes } from '@sku-private/test-utils';

export default {
srcPaths: ['src', 'sku-ssr.config.ts'],
Expand All @@ -8,4 +10,5 @@ export default {
publicPath: '/static/typescript',
setupTests: 'src/setupTests.ts',
target: 'dist',
dangerouslySetWebpackConfig: (config) => makeStableHashes(config),
} satisfies SkuConfig;
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { ListExternalsWebpackPlugin } = require('./ListExternalsWebpackPlugin');
const appSnapshot = require('./appSnapshot');
const { startAssetServer } = require('./assetServer');
const { dirContentsToObject } = require('./dirContentsToObject');
const { makeStableHashes } = require('./skuConfig');
const {
getStorybookFrame,
getTextContentFromStorybookFrame,
Expand All @@ -17,6 +18,7 @@ module.exports = {
dirContentsToObject,
getStorybookFrame,
getTextContentFromStorybookFrame,
makeStableHashes,
runSkuScriptInDir,
spawnSkuScriptInDir,
waitForUrls,
Expand Down
19 changes: 19 additions & 0 deletions test-utils/skuConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const makeStableHashes = (config) => {
// Addresses an issue where module IDs were different between local dev and CI
config.optimization.chunkIds = 'natural';
config.optimization.moduleIds = 'natural';

// Disable hashes
if (config.output.filename?.includes('[contenthash]')) {
config.output.filename = '[name].js';
}
if (config.output.chunkFilename?.includes('[contenthash]')) {
config.output.chunkFilename = '[name].chunk.js';
}

return config;
};

module.exports = {
makeStableHashes,
};
Loading

0 comments on commit c7b6e02

Please sign in to comment.