Skip to content

Commit

Permalink
test: use inline snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 21, 2022
1 parent 8808f37 commit 389e6d2
Showing 1 changed file with 83 additions and 68 deletions.
151 changes: 83 additions & 68 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { loadConfig } from '../src'
describe('c12', () => {
const r = path => fileURLToPath(new URL(path, import.meta.url))

const transformPaths = obj => JSON.parse(JSON.stringify(obj).replaceAll(r('.'), '<path>/'))

it('load fixture config', async () => {
const { config, layers } = await loadConfig({
cwd: r('./fixture'),
Expand All @@ -23,81 +25,94 @@ describe('c12', () => {
}
})

expect(config).toMatchObject({
configFile: true,
rcFile: true,
defaultConfig: true,
overriden: true,
baseConfig: true,
devConfig: true,
virtual: true,
colors: {
primary: 'user_primary',
secondary: 'theme_secondary',
text: 'base_text'
expect(transformPaths(config)).toMatchInlineSnapshot(`
{
"baseConfig": true,
"colors": {
"primary": "user_primary",
"secondary": "theme_secondary",
"text": "base_text",
},
"configFile": true,
"defaultConfig": true,
"devConfig": true,
"extends": [
"./theme",
"./config.dev",
"virtual",
],
"overriden": true,
"rcFile": true,
"virtual": true,
}
})
`)

expect(layers).toMatchObject([
{
config: {
overriden: true,
extends: [
'virtual'
]
expect(transformPaths(layers)).toMatchInlineSnapshot(`
[
{
"config": {
"extends": [
"virtual",
],
"overriden": true,
},
},
configFile: undefined,
cwd: undefined
},
{
config: {
extends: [
'./theme',
'./config.dev'
],
colors: {
primary: 'user_primary'
{
"config": {
"colors": {
"primary": "user_primary",
},
"configFile": true,
"extends": [
"./theme",
"./config.dev",
],
"overriden": false,
},
configFile: true,
overriden: false
"configFile": "config",
"cwd": "<path>/fixture",
},
configFile: 'config',
cwd: r('./fixture')
},
{
config: { rcFile: true },
configFile: '.configrc'
},
{
config: {
colors: {
primary: 'theme_primary',
secondary: 'theme_secondary'
}
{
"config": {
"rcFile": true,
},
"configFile": ".configrc",
},
configFile: r('./fixture/theme/config.ts'),
cwd: r('./fixture/theme')
},
{
config: {
baseConfig: true,
colors: {
primary: 'base_primary',
text: 'base_text'
}
{
"config": {
"colors": {
"primary": "theme_primary",
"secondary": "theme_secondary",
},
},
"configFile": "<path>/fixture/theme/config.ts",
"cwd": "<path>/fixture/theme",
},
configFile: r('./fixture/base/config.ts'),
cwd: r('./fixture/base')
},
{
config: { devConfig: true },
configFile: r('./fixture/config.dev.ts'),
cwd: r('./fixture')
},
{
config: { virtual: true }
}
])
{
"config": {
"baseConfig": true,
"colors": {
"primary": "base_primary",
"text": "base_text",
},
},
"configFile": "<path>/fixture/base/config.ts",
"cwd": "<path>/fixture/base",
},
{
"config": {
"devConfig": true,
},
"configFile": "<path>/fixture/config.dev.ts",
"cwd": "<path>/fixture",
},
{
"config": {
"virtual": true,
},
},
]
`)
})

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

0 comments on commit 389e6d2

Please sign in to comment.