diff --git a/test/all.test.js b/test/all.test.js index 996d569bff..958387d9dc 100644 --- a/test/all.test.js +++ b/test/all.test.js @@ -16,10 +16,10 @@ import './cli.test.js' import './core.test.js' import './deps.test.js' import './error.test.ts' +import './export.test.js' import './global.test.js' import './goods.test.js' import './index.test.js' import './package.test.js' import './util.test.js' -import './yaml.test.js' -import './export.test.js' +import './vendor.test.js' diff --git a/test/cli.test.js b/test/cli.test.js index ebaa02f93b..86f6565a3c 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -17,7 +17,6 @@ import { test, describe, before, after } from 'node:test' import { fileURLToPath } from 'node:url' import net from 'node:net' import getPort from 'get-port' -import '../build/globals.js' import { argv, importPath, @@ -32,6 +31,7 @@ import { transformMarkdown, writeAndImport, } from '../build/cli.js' +import { $, path, fs, tmpfile, tmpdir } from '../build/index.js' const __filename = fileURLToPath(import.meta.url) const spawn = $.spawn diff --git a/test/global.test.js b/test/global.test.js index 94bfdd04d8..a25345e2b3 100644 --- a/test/global.test.js +++ b/test/global.test.js @@ -13,11 +13,17 @@ // limitations under the License. import assert from 'node:assert' -import { test, describe } from 'node:test' +import { test, describe, after } from 'node:test' import '../build/globals.js' import * as index from '../build/index.js' describe('global', () => { + after(() => { + for (const key of Object.keys(index)) { + delete global[key] + } + }) + test('global cd()', async () => { const cwd = (await $`pwd`).toString().trim() cd('/') diff --git a/test/goods.test.js b/test/goods.test.js index dd2e60c899..6aed154606 100644 --- a/test/goods.test.js +++ b/test/goods.test.js @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import chalk from 'chalk' import assert from 'node:assert' import { test, describe } from 'node:test' -import '../build/globals.js' +import { $, chalk } from '../build/index.js' +import { echo, sleep, parseArgv } from '../build/goods.js' describe('goods', () => { function zx(script) { @@ -32,18 +32,6 @@ describe('goods', () => { assert.match((await p).stdout, /Answer is foo/) }) - test('globby() works', async () => { - assert.equal(globby, glob) - assert.deepEqual(await globby('*.md'), ['README.md']) - }) - - test('fetch() works', async () => { - assert.match( - await fetch('https://medv.io').then((res) => res.text()), - /Anton Medvedev/ - ) - }) - test('echo() works', async () => { const log = console.log let stdout = '' @@ -61,33 +49,6 @@ describe('goods', () => { assert.match(stdout, /foo/) }) - test('YAML works', async () => { - assert.deepEqual(YAML.parse(YAML.stringify({ foo: 'bar' })), { foo: 'bar' }) - }) - - test('which() available', async () => { - assert.equal(which.sync('npm'), await which('npm')) - }) - - test('minimist available', async () => { - assert.equal(typeof minimist, 'function') - }) - - test('minimist works', async () => { - assert.deepEqual( - minimist( - ['--foo', 'bar', '-a', '5', '-a', '42', '--force', './some.file'], - { boolean: 'force' } - ), - { - a: [5, 42], - foo: 'bar', - force: true, - _: ['./some.file'], - } - ) - }) - test('sleep() works', async () => { const now = Date.now() await sleep(100) diff --git a/test/package.test.js b/test/package.test.js index 3eac9452c4..a9ed6f6107 100644 --- a/test/package.test.js +++ b/test/package.test.js @@ -14,7 +14,7 @@ import assert from 'node:assert' import { test, describe, after, before } from 'node:test' -import '../build/globals.js' +import { $, within, path, glob } from '../build/index.js' const __dirname = new URL('.', import.meta.url).pathname const root = path.resolve(__dirname, '..') diff --git a/test/vendor.test.js b/test/vendor.test.js new file mode 100644 index 0000000000..7c407d8d58 --- /dev/null +++ b/test/vendor.test.js @@ -0,0 +1,67 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import assert from 'node:assert' +import { test, describe } from 'node:test' +import { + YAML, + minimist, + which, + glob, + nodeFetch as fetch, +} from '../build/vendor.js' + +describe('vendor API', () => { + test('YAML.parse', () => { + assert.deepEqual(YAML.parse('a: b\n'), { a: 'b' }) + }) + + test('YAML.stringify', () => { + assert.equal(YAML.stringify({ a: 'b' }), 'a: b\n') + }) + + test('globby() works', async () => { + assert.deepEqual(await glob('*.md'), ['README.md']) + }) + + test('fetch() works', async () => { + assert.match( + await fetch('https://medv.io').then((res) => res.text()), + /Anton Medvedev/ + ) + }) + + test('which() available', async () => { + assert.equal(which.sync('npm'), await which('npm')) + }) + + test('minimist available', async () => { + assert.equal(typeof minimist, 'function') + }) + + test('minimist works', async () => { + assert.deepEqual( + minimist( + ['--foo', 'bar', '-a', '5', '-a', '42', '--force', './some.file'], + { boolean: 'force' } + ), + { + a: [5, 42], + foo: 'bar', + force: true, + _: ['./some.file'], + } + ) + }) +}) diff --git a/test/yaml.test.js b/test/yaml.test.js deleted file mode 100644 index 3cb9775379..0000000000 --- a/test/yaml.test.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2024 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import assert from 'node:assert' -import { test, describe } from 'node:test' -import { YAML } from '../build/vendor.js' - -describe('YAML', () => { - test('YAML.parse', () => { - assert.deepEqual(YAML.parse('a: b\n'), { a: 'b' }) - }) - - test('YAML.stringify', () => { - assert.equal(YAML.stringify({ a: 'b' }), 'a: b\n') - }) -})