Skip to content

Commit 756b742

Browse files
authored
test: merge autogenerated vendor tests (google#1007)
* test: merge autogenerated vendor tests continues google#987 * test: optimize test flow
1 parent 9c84ab3 commit 756b742

12 files changed

+303
-412
lines changed

.github/workflows/test.yml

+7-13
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,27 @@ jobs:
6767
runs-on: ubuntu-latest
6868
env:
6969
FORCE_COLOR: 3
70-
strategy:
71-
matrix:
72-
node-version: [16.x, 20.x, 22.x]
70+
7371
steps:
7472
- uses: actions/checkout@v4
7573

76-
- name: Use Node.js ${{ matrix.node-version }}
74+
- name: Use Node.js 22.x
7775
uses: actions/setup-node@v4
7876
with:
79-
node-version: ${{ matrix.node-version }}
77+
node-version: 22.x
8078

8179
- uses: actions/download-artifact@v4
8280
with:
8381
name: build
8482
- run: npm ci
8583

86-
- name: Unit & types tests
87-
if: matrix.node-version == '20.x'
88-
run: |
89-
npm run test:coverage
90-
npm run test:types
91-
9284
- name: Unit tests
93-
if: matrix.node-version != '20.x'
94-
run: npm run test:unit
85+
run: npm run test:coverage
9586
timeout-minutes: 1
9687

88+
- name: Type tests
89+
run: npm run test:types
90+
9791
smoke-win32-node16:
9892
runs-on: windows-latest
9993
needs: build

scripts/build-tests.mjs

+15-12
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,37 @@ import fs from 'node:fs'
1818
import path from 'node:path'
1919
import * as vendor from '../build/vendor.js'
2020

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, '../..')
2322
const apis = ['chalk', 'depseek', 'fs', 'minimist', 'ps', 'which', 'YAML']
24-
2523
const copyright = await fs.readFileSync(
2624
path.resolve(root, 'test/fixtures/copyright.txt'),
2725
'utf8'
2826
)
2927

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+
3137
apis.forEach((name) => {
3238
const api = vendor[name]
3339
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}')`
3542
const methodChecks = methods.length
3643
? '\n' + methods.map(([k, v]) => formatAssert(k, v)).join('\n')
3744
: ''
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 += `
4446
describe('vendor ${name} API ', () => {
4547
test('exports', () => {
4648
assert.equal(typeof ${name}, '${typeof api}')${methodChecks}
4749
})
4850
})
4951
`
50-
fs.writeFileSync(filePath, fileContents)
5152
})
53+
54+
fs.writeFileSync(filePath, fileContents)

test/all.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ import './goods.test.js'
2020
import './index.test.js'
2121
import './package.test.js'
2222
import './util.test.js'
23-
import './vendor.test.js'
23+
import './vendor-yaml.test.js'
24+
import './vendor-export.test.js'

test/vendor-chalk.test.js

-24
This file was deleted.

test/vendor-depseek.test.js

-23
This file was deleted.

0 commit comments

Comments
 (0)