Skip to content

Commit 8717c18

Browse files
committed
test: more tests
1 parent 6fd4ccc commit 8717c18

4 files changed

Lines changed: 96 additions & 6 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const sortExports = onObject((exports) => {
274274
// Move `types` to top
275275
{
276276
const index = conditions.indexOf('types')
277-
if (index !== -1) {
277+
if (index > 0) {
278278
conditions.splice(index, 1)
279279
conditions.unshift('types')
280280
}

tests/exports.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for (const deep of [false, true]) {
2323
const exports = {
2424
unknown: './unknown.unknown',
2525
'./path-not-really-makes-no-sense': {},
26-
default: './types.d.ts',
26+
default: './default.js',
2727
import: './import.mjs',
2828
}
2929

@@ -54,6 +54,22 @@ for (const deep of [false, true]) {
5454
}
5555
}
5656

57+
test(`Only 'types'`, macro.sortObject, {
58+
path: 'exports',
59+
expect: 'snapshot',
60+
value: {
61+
types: './types.d.ts',
62+
},
63+
})
64+
65+
test(`Only 'default'`, macro.sortObject, {
66+
path: 'exports',
67+
expect: 'snapshot',
68+
value: {
69+
default: './default.js',
70+
},
71+
})
72+
5773
test(`Only 'module-sync' and 'require'`, macro.sortObject, {
5874
path: 'exports',
5975
expect: 'snapshot',
@@ -62,3 +78,14 @@ test(`Only 'module-sync' and 'require'`, macro.sortObject, {
6278
'module-sync': './module-sync.mjs',
6379
},
6480
})
81+
82+
test(`Well formed`, macro.sortObject, {
83+
path: 'exports',
84+
expect: 'snapshot',
85+
value: {
86+
types: './types.d.ts',
87+
'module-sync': './module-sync.mjs',
88+
require: './require.cjs',
89+
default: './default.js',
90+
},
91+
})

tests/snapshots/exports.js.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Generated by [AVA](https://avajs.dev).
3838
"exports": {␊
3939
"unknown": "./unknown.unknown",␊
4040
"./path-not-really-makes-no-sense": {},␊
41-
"default": "./types.d.ts",␊
41+
"default": "./default.js",␊
4242
"import": "./import.mjs"␊
4343
}␊
4444
}`,
@@ -48,7 +48,7 @@ Generated by [AVA](https://avajs.dev).
4848
"./path-not-really-makes-no-sense": {},␊
4949
"unknown": "./unknown.unknown",␊
5050
"import": "./import.mjs",␊
51-
"default": "./types.d.ts"␊
51+
"default": "./default.js"␊
5252
}␊
5353
}`,
5454
pretty: true,
@@ -118,7 +118,7 @@ Generated by [AVA](https://avajs.dev).
118118
"./deep": {␊
119119
"unknown": "./unknown.unknown",␊
120120
"./path-not-really-makes-no-sense": {},␊
121-
"default": "./types.d.ts",␊
121+
"default": "./default.js",␊
122122
"import": "./import.mjs"␊
123123
}␊
124124
}␊
@@ -130,7 +130,7 @@ Generated by [AVA](https://avajs.dev).
130130
"./path-not-really-makes-no-sense": {},␊
131131
"unknown": "./unknown.unknown",␊
132132
"import": "./import.mjs",␊
133-
"default": "./types.d.ts"␊
133+
"default": "./default.js"␊
134134
}␊
135135
}␊
136136
}`,
@@ -166,6 +166,44 @@ Generated by [AVA](https://avajs.dev).
166166
pretty: true,
167167
}
168168

169+
## Only 'types'
170+
171+
> Should sort `exports` as object.
172+
173+
{
174+
input: `{␊
175+
"exports": {␊
176+
"types": "./types.d.ts"␊
177+
}␊
178+
}`,
179+
options: undefined,
180+
output: `{␊
181+
"exports": {␊
182+
"types": "./types.d.ts"␊
183+
}␊
184+
}`,
185+
pretty: true,
186+
}
187+
188+
## Only 'default'
189+
190+
> Should sort `exports` as object.
191+
192+
{
193+
input: `{␊
194+
"exports": {␊
195+
"default": "./default.js"␊
196+
}␊
197+
}`,
198+
options: undefined,
199+
output: `{␊
200+
"exports": {␊
201+
"default": "./default.js"␊
202+
}␊
203+
}`,
204+
pretty: true,
205+
}
206+
169207
## Only 'module-sync' and 'require'
170208

171209
> Should sort `exports` as object.
@@ -186,3 +224,28 @@ Generated by [AVA](https://avajs.dev).
186224
}`,
187225
pretty: true,
188226
}
227+
228+
## Well formed
229+
230+
> Should sort `exports` as object.
231+
232+
{
233+
input: `{␊
234+
"exports": {␊
235+
"types": "./types.d.ts",␊
236+
"module-sync": "./module-sync.mjs",␊
237+
"require": "./require.cjs",␊
238+
"default": "./default.js"␊
239+
}␊
240+
}`,
241+
options: undefined,
242+
output: `{␊
243+
"exports": {␊
244+
"types": "./types.d.ts",␊
245+
"module-sync": "./module-sync.mjs",␊
246+
"require": "./require.cjs",␊
247+
"default": "./default.js"␊
248+
}␊
249+
}`,
250+
pretty: true,
251+
}

tests/snapshots/exports.js.snap

122 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)