Skip to content

Commit 9246579

Browse files
committed
tsconfig/eslint fix + build
1 parent 0c6a7e7 commit 9246579

File tree

5 files changed

+62
-57
lines changed

5 files changed

+62
-57
lines changed

__tests__/main.test.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
11
import {expect, test} from '@jest/globals'
22
import {getStatsDiff} from '../src/get-stats-diff'
33
import {getChunkModuleDiff} from '../src/get-chunk-module-diff'
4-
import {getCommentBody} from '../src/to-comment-body'
54
import {
65
printAssetTablesByGroup,
76
printChunkModulesTable,
87
printTotalAssetTable
98
} from '../src/print-markdown'
109
import {AssetDiff} from '../src/types'
10+
import {readFile} from 'node:fs/promises'
11+
import {resolve} from 'node:path'
12+
import {StatsCompilation} from 'webpack'
1113

12-
test('Shows stats when files are removed', () => {
14+
async function readJsonFile(path: string): Promise<StatsCompilation> {
15+
const data = await readFile(resolve(__dirname, path), 'utf8')
16+
return JSON.parse(data)
17+
}
18+
19+
test('Shows stats when files are removed', async () => {
1320
const statsDiff = getStatsDiff(
14-
require('./__mocks__/old-stats-assets.json'),
15-
require('./__mocks__/new-stats-assets.json')
21+
await readJsonFile('./__mocks__/old-stats-assets.json'),
22+
await readJsonFile('./__mocks__/new-stats-assets.json')
1623
)
1724

1825
expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
1926
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
2027
})
2128

22-
test('Shows stats when files are added', () => {
29+
test('Shows stats when files are added', async () => {
2330
const statsDiff = getStatsDiff(
24-
require('./__mocks__/new-stats-assets.json'),
25-
require('./__mocks__/old-stats-assets.json')
31+
await readJsonFile('./__mocks__/new-stats-assets.json'),
32+
await readJsonFile('./__mocks__/old-stats-assets.json')
2633
)
2734

2835
expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
2936
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
3037
})
3138

32-
test('Shows stats when files are unchanged', () => {
39+
test('Shows stats when files are unchanged', async () => {
3340
const statsDiff = getStatsDiff(
34-
require('./__mocks__/old-stats-assets.json'),
35-
require('./__mocks__/old-stats-assets.json')
41+
await readJsonFile('./__mocks__/old-stats-assets.json'),
42+
await readJsonFile('./__mocks__/old-stats-assets.json')
3643
)
3744

3845
expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
3946
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
4047
})
4148

42-
test('computes the correct module diff information', () => {
49+
test('computes the correct module diff information', async () => {
4350
const statsDiff = getChunkModuleDiff(
44-
require('./__mocks__/old-stats-with-chunks.json'),
45-
require('./__mocks__/new-stats-with-chunks.json')
51+
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
52+
await readJsonFile('./__mocks__/new-stats-with-chunks.json')
4653
)
4754

4855
expect(statsDiff?.added).toContainEqual({
@@ -78,28 +85,28 @@ test('computes the correct module diff information', () => {
7885
expect(statsDiff?.total.diffPercentage).toEqual(0)
7986
})
8087

81-
test('displays module information when files are added/removed/changed', () => {
88+
test('displays module information when files are added/removed/changed', async () => {
8289
const statsDiff = getChunkModuleDiff(
83-
require('./__mocks__/old-stats-with-chunks.json'),
84-
require('./__mocks__/new-stats-with-chunks.json')
90+
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
91+
await readJsonFile('./__mocks__/new-stats-with-chunks.json')
8592
)
8693

8794
expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
8895
})
8996

90-
test('displays no module information when unchanged', () => {
97+
test('displays no module information when unchanged', async () => {
9198
const statsDiff = getChunkModuleDiff(
92-
require('./__mocks__/old-stats-with-chunks.json'),
93-
require('./__mocks__/old-stats-with-chunks.json')
99+
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
100+
await readJsonFile('./__mocks__/old-stats-with-chunks.json')
94101
)
95102

96103
expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
97104
})
98105

99-
test('does not display module information when it does not exist', () => {
106+
test('does not display module information when it does not exist', async () => {
100107
const statsDiff = getChunkModuleDiff(
101-
require('./__mocks__/old-stats-assets.json'),
102-
require('./__mocks__/old-stats-assets.json')
108+
await readJsonFile('./__mocks__/old-stats-assets.json'),
109+
await readJsonFile('./__mocks__/old-stats-assets.json')
103110
)
104111

105112
expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()

dist/index.js

Lines changed: 30 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"private": true,
55
"description": "Github action to compare the size of two webpack bundles from their stats.json output files",
6-
"main": "lib/main.js",
6+
"main": "lib/src/main.js",
77
"scripts": {
88
"build": "tsc",
99
"format": "prettier --write '**/*.ts'",

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
44
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
55
"outDir": "./lib" /* Redirect output structure to the directory. */,
6-
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
76
"strict": true /* Enable all strict type-checking options. */,
87
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
98
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
109
},
11-
"exclude": ["node_modules", "**/*.test.ts"]
10+
"exclude": ["node_modules"]
1211
}

0 commit comments

Comments
 (0)