@financial-times/dotcom-build-code-splitting 8.2.2 → 8.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/dotcom-build-code-splitting",
3
- "version": "8.2.2",
3
+ "version": "8.2.3",
4
4
  "description": "",
5
5
  "main": "dist/node/index.js",
6
6
  "types": "src/index.ts",
@@ -1,36 +1,30 @@
1
- import { PageKitCodeSplittingPlugin } from '../index'
2
- import webpack from 'webpack'
1
+ import { promisify } from 'util'
2
+ import webpack, { Configuration as WebpackConfiguration, Stats } from 'webpack'
3
3
  import path from 'path'
4
+ import { PageKitCodeSplittingPlugin } from '../index'
4
5
 
5
6
  describe('dotcom-build-code-splitting', () => {
7
+ const webpackAsync = promisify(webpack)
6
8
  it('create chunk for privacy modules', async () => {
7
- await new Promise((resolve) =>
8
- webpack(
9
- {
10
- mode: 'none',
11
- entry: {
12
- scripts: path.join(__dirname, '/__fixtures__', 'entry-point.js')
13
- },
14
- output: {
15
- filename: '[name].js',
16
- path: path.join(__dirname, '/tmp')
17
- },
18
- plugins: [new PageKitCodeSplittingPlugin()]
19
- },
20
- function (error, stats) {
21
- if (error) {
22
- throw error
23
- } else if (stats.hasErrors()) {
24
- throw stats.toString()
25
- }
26
-
27
- const files = stats.toJson().assets.map((asset) => asset.name)
9
+ const webpackConfig: WebpackConfiguration = {
10
+ mode: 'none',
11
+ entry: {
12
+ scripts: path.join(__dirname, '/__fixtures__', 'entry-point.js')
13
+ },
14
+ output: {
15
+ filename: '[name].js',
16
+ path: path.join(__dirname, '/tmp')
17
+ },
18
+ plugins: [new PageKitCodeSplittingPlugin()]
19
+ }
20
+ const result = (await webpackAsync([webpackConfig])) as { stats: [Stats] }
28
21
 
29
- expect(files).toEqual(expect.arrayContaining(['privacy-components.js']))
22
+ const stats = result.stats[0].toJson()
23
+ if (!stats) {
24
+ throw new Error('No stats')
25
+ }
26
+ const files = stats.assets?.map((asset) => asset.name) as string[]
30
27
 
31
- resolve()
32
- }
33
- )
34
- )
28
+ expect(files.find((file) => file.includes('privacy-components'))).toBeTruthy()
35
29
  })
36
30
  })