@@ -18,34 +18,37 @@ import fs from 'node:fs'
18
18
import path from 'node:path'
19
19
import * as vendor from '../build/vendor.js'
20
20
21
- const __dirname = path . dirname ( new URL ( import . meta. url ) . pathname )
22
- const root = path . resolve ( __dirname , '..' )
21
+ const root = path . resolve ( new URL ( import . meta. url ) . pathname , '../..' )
23
22
const apis = [ 'chalk' , 'depseek' , 'fs' , 'minimist' , 'ps' , 'which' , 'YAML' ]
24
-
25
23
const copyright = await fs . readFileSync (
26
24
path . resolve ( root , 'test/fixtures/copyright.txt' ) ,
27
25
'utf8'
28
26
)
29
27
30
- // prettier-ignore
28
+ const filePath = path . resolve ( root , `test/vendor-export.test.js` )
29
+ let fileContents = `${ copyright . replace ( 'YEAR' , new Date ( ) . getFullYear ( ) ) }
30
+ import assert from 'node:assert'
31
+ import { test, describe } from 'node:test'
32
+ import {
33
+ ${ apis . map ( ( v ) => ' ' + v ) . join ( ',\n' ) } ,
34
+ } from '../build/vendor.js'
35
+ `
36
+
31
37
apis . forEach ( ( name ) => {
32
38
const api = vendor [ name ]
33
39
const methods = Object . entries ( api )
34
- const formatAssert = ( k , v , prefix = ' ' ) => `${ prefix } assert.equal(typeof ${ name } .${ k } , '${ typeof v } ')`
40
+ const formatAssert = ( k , v , prefix = ' ' ) =>
41
+ `${ prefix } assert.equal(typeof ${ name } .${ k } , '${ typeof v } ', '${ name } .${ k } ')`
35
42
const methodChecks = methods . length
36
43
? '\n' + methods . map ( ( [ k , v ] ) => formatAssert ( k , v ) ) . join ( '\n' )
37
44
: ''
38
- const filePath = path . resolve ( root , `test/vendor-${ name . toLowerCase ( ) } .test.js` )
39
- const fileContents = `${ copyright . replace ( 'YEAR' , new Date ( ) . getFullYear ( ) ) }
40
- import assert from 'node:assert'
41
- import { test, describe } from 'node:test'
42
- import { ${ name } } from '../build/vendor.js'
43
-
45
+ fileContents += `
44
46
describe('vendor ${ name } API ', () => {
45
47
test('exports', () => {
46
48
assert.equal(typeof ${ name } , '${ typeof api } ')${ methodChecks }
47
49
})
48
50
})
49
51
`
50
- fs . writeFileSync ( filePath , fileContents )
51
52
} )
53
+
54
+ fs . writeFileSync ( filePath , fileContents )
0 commit comments