Skip to content

Commit 389e6d2

Browse files
committed
test: use inline snapshots
1 parent 8808f37 commit 389e6d2

File tree

1 file changed

+83
-68
lines changed

1 file changed

+83
-68
lines changed

test/index.test.ts

+83-68
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { loadConfig } from '../src'
55
describe('c12', () => {
66
const r = path => fileURLToPath(new URL(path, import.meta.url))
77

8+
const transformPaths = obj => JSON.parse(JSON.stringify(obj).replaceAll(r('.'), '<path>/'))
9+
810
it('load fixture config', async () => {
911
const { config, layers } = await loadConfig({
1012
cwd: r('./fixture'),
@@ -23,81 +25,94 @@ describe('c12', () => {
2325
}
2426
})
2527

26-
expect(config).toMatchObject({
27-
configFile: true,
28-
rcFile: true,
29-
defaultConfig: true,
30-
overriden: true,
31-
baseConfig: true,
32-
devConfig: true,
33-
virtual: true,
34-
colors: {
35-
primary: 'user_primary',
36-
secondary: 'theme_secondary',
37-
text: 'base_text'
28+
expect(transformPaths(config)).toMatchInlineSnapshot(`
29+
{
30+
"baseConfig": true,
31+
"colors": {
32+
"primary": "user_primary",
33+
"secondary": "theme_secondary",
34+
"text": "base_text",
35+
},
36+
"configFile": true,
37+
"defaultConfig": true,
38+
"devConfig": true,
39+
"extends": [
40+
"./theme",
41+
"./config.dev",
42+
"virtual",
43+
],
44+
"overriden": true,
45+
"rcFile": true,
46+
"virtual": true,
3847
}
39-
})
48+
`)
4049

41-
expect(layers).toMatchObject([
42-
{
43-
config: {
44-
overriden: true,
45-
extends: [
46-
'virtual'
47-
]
50+
expect(transformPaths(layers)).toMatchInlineSnapshot(`
51+
[
52+
{
53+
"config": {
54+
"extends": [
55+
"virtual",
56+
],
57+
"overriden": true,
58+
},
4859
},
49-
configFile: undefined,
50-
cwd: undefined
51-
},
52-
{
53-
config: {
54-
extends: [
55-
'./theme',
56-
'./config.dev'
57-
],
58-
colors: {
59-
primary: 'user_primary'
60+
{
61+
"config": {
62+
"colors": {
63+
"primary": "user_primary",
64+
},
65+
"configFile": true,
66+
"extends": [
67+
"./theme",
68+
"./config.dev",
69+
],
70+
"overriden": false,
6071
},
61-
configFile: true,
62-
overriden: false
72+
"configFile": "config",
73+
"cwd": "<path>/fixture",
6374
},
64-
configFile: 'config',
65-
cwd: r('./fixture')
66-
},
67-
{
68-
config: { rcFile: true },
69-
configFile: '.configrc'
70-
},
71-
{
72-
config: {
73-
colors: {
74-
primary: 'theme_primary',
75-
secondary: 'theme_secondary'
76-
}
75+
{
76+
"config": {
77+
"rcFile": true,
78+
},
79+
"configFile": ".configrc",
7780
},
78-
configFile: r('./fixture/theme/config.ts'),
79-
cwd: r('./fixture/theme')
80-
},
81-
{
82-
config: {
83-
baseConfig: true,
84-
colors: {
85-
primary: 'base_primary',
86-
text: 'base_text'
87-
}
81+
{
82+
"config": {
83+
"colors": {
84+
"primary": "theme_primary",
85+
"secondary": "theme_secondary",
86+
},
87+
},
88+
"configFile": "<path>/fixture/theme/config.ts",
89+
"cwd": "<path>/fixture/theme",
8890
},
89-
configFile: r('./fixture/base/config.ts'),
90-
cwd: r('./fixture/base')
91-
},
92-
{
93-
config: { devConfig: true },
94-
configFile: r('./fixture/config.dev.ts'),
95-
cwd: r('./fixture')
96-
},
97-
{
98-
config: { virtual: true }
99-
}
100-
])
91+
{
92+
"config": {
93+
"baseConfig": true,
94+
"colors": {
95+
"primary": "base_primary",
96+
"text": "base_text",
97+
},
98+
},
99+
"configFile": "<path>/fixture/base/config.ts",
100+
"cwd": "<path>/fixture/base",
101+
},
102+
{
103+
"config": {
104+
"devConfig": true,
105+
},
106+
"configFile": "<path>/fixture/config.dev.ts",
107+
"cwd": "<path>/fixture",
108+
},
109+
{
110+
"config": {
111+
"virtual": true,
112+
},
113+
},
114+
]
115+
`)
101116
})
102117

103118
it('extend from git repo', async () => {

0 commit comments

Comments
 (0)