8000 test: check pkg entries exports by antongolub · Pull Request #1021 · google/zx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: check pkg entries exports #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 34 additions & 35 deletions scripts/build-tests.mjs
< 8000 table class=" diff-table js-diff-table tab-size " data-tab-size="8" data-diff-anchor="diff-bf56ef2a50362f38c76cfb1e27b63b155472c950b5a42cc24491e9e82cc2b601" data-paste-markdown-skip> Original file line number Diff line number Diff line change Expand Up @@ -17,48 +17,47 @@ import fs from 'node:fs' import path from 'node:path' import * as vendor from '../build/vendor.js' import * as core from '../build/core.js' import * as cli from '../build/cli.js' import * as index from '../build/index.js'
const root = path.resolve(new URL(import.meta.url).pathname, '../..') const apis = [ 'chalk', 'depseek', 'fs', 'glob', 'minimist', 'ps', 'which', 'YAML', // prettier-ignore const modules = [ ['core', core], ['cli', cli], ['index', index], ['vendor', vendor, ['chalk', 'depseek', 'fs', 'glob', 'minimist', 'ps', 'which', 'YAML',]], ] const root = path.resolve(new URL(import.meta.url).pathname, '../..') const filePath = path.resolve(root, `test/export.test.js`)
const copyright = await fs.readFileSync( path.resolve(root, 'test/fixtures/copyright.txt'), 'utf8' )
const filePath = path.resolve(root, `test/vendor-export.test.js`) let fileContents = `${copyright.replace('YEAR', new Date().getFullYear())} let head = `${copyright.replace('YEAR', new Date().getFullYear())} import assert from 'node:assert' import { test, describe } from 'node:test' import { ${apis.map((v) => ' ' + v).join(',\n')}, } from '../build/vendor.js' ` import { test, describe } from 'node:test'` let body = '\n'
for (const [name, ref, apis = Object.keys(ref).sort()] of modules) { head += `\nimport * as ${name} from '../build/${name}.js'` body += `\n//prettier-ignore\ndescribe('${name}', () => {\n` body += ` test('exports', () => {\n` for (const r of apis) { const api = ref[r] body += ` assert.equal(typeof ${name}.${r}, '${typeof api}', '${name}.${r}')\n` if (typeof api !== 'fun 8000 ction' && typeof api !== 'object') continue for (const k of Object.keys(api).sort()) { const v = api[k] body += ` assert.equal(typeof ${name}.${r}.${k}, '${typeof v}', '${name}.${r}.${k}')\n` } } body += ' })\n' body += '})\n' }
apis.forEach((name) => { const api = vendor[name] const methods = Object.entries(api) const formatAssert = (k, v, prefix = ' ') => `${prefix}assert.equal(typeof ${name}.${k}, '${typeof v}', '${name}.${k}')` const methodChecks = methods.length ? '\n' + methods.map(([k, v]) => formatAssert(k, v)).join('\n') : '' fileContents += ` describe('vendor ${name} API ', () => { // prettier-ignore test('exports', () => { assert.equal(typeof ${name}, '${typeof api}')${methodChecks} }) }) ` }) const contents = head + body
fs.writeFileSync(filePath, fileContents) fs.writeFileSync(filePath, contents)
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function main() {
await runScript(argv.eval, argv.ext)
return
}
const firstArg = argv._[0]
const [firstArg] = argv._
updateArgv(argv._.slice(firstArg === undefined ? 0 : 1))
if (!firstArg || firstArg === '-') {
const success = await scriptFromStdin(argv.ext)
Expand Down
3 changes: 2 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const CWD = Symbol('processCwd')
const SYNC = Symbol('syncExec')
const EOL = Buffer.from(_EOL)
const SIGTERM = 'SIGTERM'
const ENV_PREFIX = 'ZX_'
const storage = new AsyncLocalStorage<Options>()

function getStore() {
Expand Down Expand Up @@ -857,7 +858,7 @@ const promisifyStream = <S extends Writable>(

export function resolveDefaults(
defs: Options,
prefix: string = 'ZX_',
prefix: string = ENV_PREFIX,
env = process.env
) {
const allowed = new Set([
Expand Down
4 changes: 2 additions & 2 deletions test/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import './goods.test.js'
import './index.test.js'
import './package.test.js'
import './util.test.js'
import './vendor-yaml.test.js'
import './vendor-export.test.js'
import './yaml.test.js'
import './export.test.js'
17 changes: 15 additions & 2 deletions test/cli.test.js
ED48
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ import { fileURLToPath } from 'node:url'
import net from 'node:net'
import getPort from 'get-port'
import '../build/globals.js'
import { isMain, normalizeExt, transformMarkdown } from '../build/cli.js'
import {
argv,
importPath,
injectGlobalRequire,
isMain,
main,
normalizeExt,
runScript,
printUsage,
scriptFromStdin,
scriptFromHttp,
transformMarkdown,
writeAndImport,
} from '../build/cli.js'

const __filename = fileURLToPath(import.meta.url)
const spawn = $.spawn
Expand All @@ -38,7 +51,7 @@ const getServer = (resp = [], log = console.log) => {
}

describe('cli', () => {
// Helps detect unresolved ProcessPromise.
// Helps to detect unresolved ProcessPromise.
before(() => {
const spawned = []
$.spawn = (...args) => {
Expand Down
13 changes: 11 additions & 2 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ import { WriteStream } from 'node:fs'
import { Readable, Transform, Writable } from 'node:stream'
import { Socket } from 'node:net'
import {
$,
ProcessPromise,
ProcessOutput,
resolveDefaults,
} from '../build/index.js'
import '../build/globals.js'
cd,
syncProcessCwd,
log,
kill,
defaults,
within,
usePowerShell,
usePwsh,
useBash,
} from '../build/core.js'

describe('core', () => {
describe('resolveDefaults()', () => {
Expand Down
Loading
Loading
0