diff --git a/package.json b/package.json index acf30a45..e6278b8f 100644 --- a/package.json +++ b/package.json @@ -119,8 +119,7 @@ "node_modules" ], "moduleNameMapper": { - "^bunchee$": "/src/index.ts", - "^testing-utils$": "/test/integration/utils.ts" + "^bunchee$": "/src/index.ts" }, "transform": { "^.+\\.(t|j)sx?$": [ diff --git a/test/typing.test.ts b/src/typing.test.ts similarity index 89% rename from test/typing.test.ts rename to src/typing.test.ts index 411f762e..368ca227 100644 --- a/test/typing.test.ts +++ b/src/typing.test.ts @@ -1,5 +1,5 @@ // Import from generated files instead of using tsconfig alias -import { bundle, type BundleConfig } from 'bunchee' +import { bundle, type BundleConfig } from './index' describe('types', () => { it('should be able to import the node API and use correct typings', async () => { diff --git a/test/unit/exports.regacy-test.ts b/test/_legacy/exports.test.txt similarity index 100% rename from test/unit/exports.regacy-test.ts rename to test/_legacy/exports.test.txt diff --git a/test/cli/basic/index.test.ts b/test/cli/basic/index.test.ts index b70f4ef8..29f743f1 100644 --- a/test/cli/basic/index.test.ts +++ b/test/cli/basic/index.test.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli basic should work properly`, async () => { diff --git a/test/cli/cjs-relative-imports/index.test.ts b/test/cli/cjs-relative-imports/index.test.ts index 5c2f5382..baf6c8e8 100644 --- a/test/cli/cjs-relative-imports/index.test.ts +++ b/test/cli/cjs-relative-imports/index.test.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli cjs-relative-imports should work properly`, async () => { diff --git a/test/cli/dts-bundle/index.test.ts b/test/cli/dts-bundle/index.test.ts index 88852c38..c65946ab 100644 --- a/test/cli/dts-bundle/index.test.ts +++ b/test/cli/dts-bundle/index.test.ts @@ -1,8 +1,7 @@ import fs from 'fs' import fsp from 'fs/promises' import { join } from 'path' -import { createCliTest } from '../utils' -import { deleteFile } from '../../testing-utils' +import { createCliTest, deleteFile } from '../../testing-utils' describe('cli', () => { const dir = __dirname diff --git a/test/cli/dts/index.test.ts b/test/cli/dts/index.test.ts index 9b42bf8c..6726ce9f 100644 --- a/test/cli/dts/index.test.ts +++ b/test/cli/dts/index.test.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli dts should work properly`, async () => { diff --git a/test/cli/env-var/index.test.ts b/test/cli/env-var/index.test.ts index 853736f3..b24b0839 100644 --- a/test/cli/env-var/index.test.ts +++ b/test/cli/env-var/index.test.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli env-var should work properly`, async () => { diff --git a/test/cli/externals/index.test.ts b/test/cli/externals/index.test.ts index d95e5d32..ab8a76f9 100644 --- a/test/cli/externals/index.test.ts +++ b/test/cli/externals/index.test.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli external should work properly`, async () => { diff --git a/test/cli/no-dts/index.test.ts b/test/cli/no-dts/index.test.ts index 556ee526..dc2dccd7 100644 --- a/test/cli/no-dts/index.test.ts +++ b/test/cli/no-dts/index.test.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli no-dts option should work properly`, async () => { diff --git a/test/cli/no-entry/index.test.ts b/test/cli/no-entry/index.test.ts index 9ab578b0..5f3eb831 100644 --- a/test/cli/no-entry/index.test.ts +++ b/test/cli/no-entry/index.test.ts @@ -1,4 +1,4 @@ -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli no-entry should work properly`, async () => { diff --git a/test/cli/output-in-watch/index.test.ts b/test/cli/output-in-watch/index.test.ts index 25f3fb3b..3fa3b05c 100644 --- a/test/cli/output-in-watch/index.test.ts +++ b/test/cli/output-in-watch/index.test.ts @@ -1,4 +1,4 @@ -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli output-in-watch should work properly`, async () => { diff --git a/test/cli/target/index.test.ts b/test/cli/target/index.test.ts index 7df6ecb7..746e2712 100644 --- a/test/cli/target/index.test.ts +++ b/test/cli/target/index.test.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' describe('cli', () => { it(`cli es2020-target should work properly`, async () => { diff --git a/test/cli/workspace/index.test.ts b/test/cli/workspace/index.test.ts index ec6d4eb3..d2100c9c 100644 --- a/test/cli/workspace/index.test.ts +++ b/test/cli/workspace/index.test.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { createCliTest } from '../utils' +import { createCliTest } from '../../testing-utils' import path from 'path' describe('cli', () => { diff --git a/test/fixtures/integration-test-template/index.test.ts b/test/fixtures/integration-test-template/index.test.ts index 0e1beedb..26ccd7e9 100644 --- a/test/fixtures/integration-test-template/index.test.ts +++ b/test/fixtures/integration-test-template/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertContainFiles } from 'testing-utils' +import { createIntegrationTest, assertContainFiles } from '../../testing-utils' describe('integration - ', () => { it('should work', async () => { diff --git a/test/integration/basic-jsx/index.test.ts b/test/integration/basic-jsx/index.test.ts index 91ec46e6..7e52be9a 100644 --- a/test/integration/basic-jsx/index.test.ts +++ b/test/integration/basic-jsx/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertContainFiles } from '../utils' +import { createIntegrationTest, assertContainFiles } from '../../testing-utils' describe('integration basic-jsx', () => { it('should work with basic JSX format', async () => { diff --git a/test/integration/bin/cts/index.test.ts b/test/integration/bin/cts/index.test.ts index dd5284fb..4cd5d595 100644 --- a/test/integration/bin/cts/index.test.ts +++ b/test/integration/bin/cts/index.test.ts @@ -1,4 +1,7 @@ -import { assertFilesContent, createIntegrationTest } from '../../utils' +import { + assertFilesContent, + createIntegrationTest, +} from '../../../testing-utils' describe('integration bin/cts', () => { it('should work with bin as .cts extension', async () => { diff --git a/test/integration/bin/multi-path/index.test.ts b/test/integration/bin/multi-path/index.test.ts index 617251b1..be441212 100644 --- a/test/integration/bin/multi-path/index.test.ts +++ b/test/integration/bin/multi-path/index.test.ts @@ -2,7 +2,7 @@ import { assertFilesContent, createIntegrationTest, isWindows, -} from '../../utils' +} from '../../../testing-utils' describe('integration bin/multi-path', () => { // TODO: handle the transform error on windows diff --git a/test/integration/bin/patch-binary/index.test.ts b/test/integration/bin/patch-binary/index.test.ts index 5d7a7345..9e8ff8ee 100644 --- a/test/integration/bin/patch-binary/index.test.ts +++ b/test/integration/bin/patch-binary/index.test.ts @@ -2,7 +2,7 @@ import { createIntegrationTest, assertContainFiles, assertFilesContent, -} from '../../utils' +} from '../../../testing-utils' describe('integration bin/patch-binary', () => { it('should patch binary directive', async () => { diff --git a/test/integration/bin/single-path/index.test.ts b/test/integration/bin/single-path/index.test.ts index 978f8f4f..facb1ba8 100644 --- a/test/integration/bin/single-path/index.test.ts +++ b/test/integration/bin/single-path/index.test.ts @@ -4,7 +4,7 @@ import { assertFilesContent, getFileNamesFromDirectory, isWindows, -} from '../../utils' +} from '../../../testing-utils' describe('integration bin/single-path', () => { // TODO: handle the transform error on windows diff --git a/test/integration/browserslist/index.test.ts b/test/integration/browserslist/index.test.ts index fa2d7742..4aca0a14 100644 --- a/test/integration/browserslist/index.test.ts +++ b/test/integration/browserslist/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('browserslist', () => { it('should work with basic JSX format', async () => { diff --git a/test/integration/conflicted-entry/conflicted-entry.test.ts b/test/integration/conflicted-entry/conflicted-entry.test.ts index 31e856a6..4295e60c 100644 --- a/test/integration/conflicted-entry/conflicted-entry.test.ts +++ b/test/integration/conflicted-entry/conflicted-entry.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' describe('integration - conflicted-entry', () => { it('should error on conflicted entries', async () => { diff --git a/test/integration/default-node-mjs/index.test.ts b/test/integration/default-node-mjs/index.test.ts index 2fca424b..9fd7b2dd 100644 --- a/test/integration/default-node-mjs/index.test.ts +++ b/test/integration/default-node-mjs/index.test.ts @@ -1,5 +1,5 @@ import { readFile } from 'fs/promises' -import { createIntegrationTest, existsFile } from '../utils' +import { createIntegrationTest, existsFile } from '../../testing-utils' describe('integration default-node-mjs', () => { it('should work with .mjs extension', async () => { diff --git a/test/integration/dev-prod-convention-reexport/index.test.ts b/test/integration/dev-prod-convention-reexport/index.test.ts index e260babc..b4b65e1f 100644 --- a/test/integration/dev-prod-convention-reexport/index.test.ts +++ b/test/integration/dev-prod-convention-reexport/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('integration dev-prod-convention-reexport', () => { it('should work with dev and prod optimize conditions', async () => { diff --git a/test/integration/dev-prod-convention/index.test.ts b/test/integration/dev-prod-convention/index.test.ts index acd48cef..e70ff04b 100644 --- a/test/integration/dev-prod-convention/index.test.ts +++ b/test/integration/dev-prod-convention/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('integration dev-prod-convention', () => { it('should work with dev and prod optimize conditions', async () => { diff --git a/test/integration/dev-prod-nested-convention/index.test.ts b/test/integration/dev-prod-nested-convention/index.test.ts index 742a1c02..3173645c 100644 --- a/test/integration/dev-prod-nested-convention/index.test.ts +++ b/test/integration/dev-prod-nested-convention/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('integration dev-prod-nested-convention', () => { it('should work with dev and prod optimize conditions', async () => { diff --git a/test/integration/dev-prod-special-convention/index.test.ts b/test/integration/dev-prod-special-convention/index.test.ts index f68c5c55..e9e2497b 100644 --- a/test/integration/dev-prod-special-convention/index.test.ts +++ b/test/integration/dev-prod-special-convention/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('integration dev-prod-special-convention', () => { it('should work with dev prod and special optimize conditions', async () => { diff --git a/test/integration/duplicate-entries-partial-specified/index.test.ts b/test/integration/duplicate-entries-partial-specified/index.test.ts index 8d983f12..383c5a23 100644 --- a/test/integration/duplicate-entries-partial-specified/index.test.ts +++ b/test/integration/duplicate-entries-partial-specified/index.test.ts @@ -1,4 +1,7 @@ -import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' +import { + createIntegrationTest, + getFileNamesFromDirectory, +} from '../../testing-utils' describe('integration duplicate-entries-partial-specified', () => { it('should not generate js types paths if not specified', async () => { diff --git a/test/integration/dynamic-require/dynamic-require.test.ts b/test/integration/dynamic-require/dynamic-require.test.ts index 593d0645..03eca612 100644 --- a/test/integration/dynamic-require/dynamic-require.test.ts +++ b/test/integration/dynamic-require/dynamic-require.test.ts @@ -1,5 +1,8 @@ import fs from 'fs' -import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' +import { + createIntegrationTest, + getFileNamesFromDirectory, +} from '../../testing-utils' describe('integration - dynamic-require', () => { it('should work', async () => { diff --git a/test/integration/edge-variable/index.test.ts b/test/integration/edge-variable/index.test.ts index 92b322b1..bd04cce5 100644 --- a/test/integration/edge-variable/index.test.ts +++ b/test/integration/edge-variable/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('integration edge-variable', () => { it('should work with edge export condition', async () => { diff --git a/test/integration/entry-index-index/index.test.ts b/test/integration/entry-index-index/index.test.ts index 61e0da24..966d1bf9 100644 --- a/test/integration/entry-index-index/index.test.ts +++ b/test/integration/entry-index-index/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertFilesContent } from '../utils' +import { createIntegrationTest, assertFilesContent } from '../../testing-utils' describe('integration entry-index-index', () => { it('should work with index file inside index directory', async () => { diff --git a/test/integration/esm-pkg-cjs-main-field/index.test.ts b/test/integration/esm-pkg-cjs-main-field/index.test.ts index f34f0bac..bcf9b1f4 100644 --- a/test/integration/esm-pkg-cjs-main-field/index.test.ts +++ b/test/integration/esm-pkg-cjs-main-field/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertContainFiles } from '../utils' +import { createIntegrationTest, assertContainFiles } from '../../testing-utils' describe('integration esm-pkg-cjs-main-field', () => { it('should work with ESM package with CJS main field ', async () => { diff --git a/test/integration/esm-shims/index.test.ts b/test/integration/esm-shims/index.test.ts index c98b6453..67c7b7ed 100644 --- a/test/integration/esm-shims/index.test.ts +++ b/test/integration/esm-shims/index.test.ts @@ -2,7 +2,7 @@ import { createIntegrationTest, assertFilesContent, getFileContents, -} from '../utils' +} from '../../testing-utils' describe('integration esm-shims', () => { it('should work with ESM shims', async () => { diff --git a/test/integration/externals/index.test.ts b/test/integration/externals/index.test.ts index d813cfd8..7ed524d9 100644 --- a/test/integration/externals/index.test.ts +++ b/test/integration/externals/index.test.ts @@ -1,5 +1,5 @@ import { readFile } from 'fs/promises' -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' describe('integration externals', () => { it('should handle externals', async () => { diff --git a/test/integration/import-fallback/index.test.ts b/test/integration/import-fallback/index.test.ts index ac412f6b..b965ef13 100644 --- a/test/integration/import-fallback/index.test.ts +++ b/test/integration/import-fallback/index.test.ts @@ -1,5 +1,5 @@ import { readFile } from 'fs/promises' -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' describe('integration import fallback', () => { it('should handle import fallback', async () => { diff --git a/test/integration/js-bad-configured-types/index.test.ts b/test/integration/js-bad-configured-types/index.test.ts index 85f257af..3f5ca3e3 100644 --- a/test/integration/js-bad-configured-types/index.test.ts +++ b/test/integration/js-bad-configured-types/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' describe('integration js-bad-configured-types', () => { it('should error when types is not correctly configured', async () => { diff --git a/test/integration/js-only/index.test.ts b/test/integration/js-only/index.test.ts index 33424c04..3539d7c1 100644 --- a/test/integration/js-only/index.test.ts +++ b/test/integration/js-only/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, existsFile } from '../utils' +import { createIntegrationTest, existsFile } from '../../testing-utils' describe('integration js-only', () => { beforeEach(() => { diff --git a/test/integration/lint/cjs-pkg-esm-main-field/index.test.ts b/test/integration/lint/cjs-pkg-esm-main-field/index.test.ts index f2c75431..18240f87 100644 --- a/test/integration/lint/cjs-pkg-esm-main-field/index.test.ts +++ b/test/integration/lint/cjs-pkg-esm-main-field/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../../utils' +import { createIntegrationTest } from '../../../testing-utils' describe('integration cjs-pkg-esm-main-field', () => { it('should warn if main field with .mjs extension in CJS package', async () => { diff --git a/test/integration/lint/invalid-exports-cjs/index.test.ts b/test/integration/lint/invalid-exports-cjs/index.test.ts index 274bdb25..33a161cf 100644 --- a/test/integration/lint/invalid-exports-cjs/index.test.ts +++ b/test/integration/lint/invalid-exports-cjs/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../../utils' +import { createIntegrationTest } from '../../../testing-utils' describe('integration invalid-exports-cjs', () => { it('should warn on invalid exports as CJS', async () => { diff --git a/test/integration/lint/invalid-exports-esm/index.test.ts b/test/integration/lint/invalid-exports-esm/index.test.ts index 6721e318..a4d10285 100644 --- a/test/integration/lint/invalid-exports-esm/index.test.ts +++ b/test/integration/lint/invalid-exports-esm/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../../utils' +import { createIntegrationTest } from '../../../testing-utils' describe('integration invalid-exports-esm', () => { it('should warn on invalid exports as ESM', async () => { diff --git a/test/integration/lint/missing-files-exports/index.test.ts b/test/integration/lint/missing-files-exports/index.test.ts index d202a37e..146a04c1 100644 --- a/test/integration/lint/missing-files-exports/index.test.ts +++ b/test/integration/lint/missing-files-exports/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../../utils' +import { createIntegrationTest } from '../../../testing-utils' describe('integration - lint - missing-files-exports', () => { it('should warn on missing files', async () => { diff --git a/test/integration/lint/missing-files-main/index.test.ts b/test/integration/lint/missing-files-main/index.test.ts index ae26caba..6d271c17 100644 --- a/test/integration/lint/missing-files-main/index.test.ts +++ b/test/integration/lint/missing-files-main/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest } from '../../utils' +import { createIntegrationTest } from '../../../testing-utils' describe('integration - lint - missing-files-main', () => { it('should warn on missing files', async () => { diff --git a/test/integration/lint/single-entry/index.test.ts b/test/integration/lint/single-entry/index.test.ts index 5bb00824..13e19821 100644 --- a/test/integration/lint/single-entry/index.test.ts +++ b/test/integration/lint/single-entry/index.test.ts @@ -3,7 +3,7 @@ import { assertFilesContent, stripANSIColor, } from '../../../testing-utils' -import { createIntegrationTest } from '../../utils' +import { createIntegrationTest } from '../../../testing-utils' describe('integration single-entry', () => { it('should warn on invalid exports as CJS', async () => { diff --git a/test/integration/mixed-directives/mixed-directives.test.ts b/test/integration/mixed-directives/mixed-directives.test.ts index 2e65f0c7..9f91c465 100644 --- a/test/integration/mixed-directives/mixed-directives.test.ts +++ b/test/integration/mixed-directives/mixed-directives.test.ts @@ -1,5 +1,8 @@ import { readFileSync } from 'fs' -import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' +import { + createIntegrationTest, + getFileNamesFromDirectory, +} from '../../testing-utils' describe('integration - mixed-directives', () => { it('should work with js only project', async () => { diff --git a/test/integration/monorepo-composite-no-incremental/index.test.ts b/test/integration/monorepo-composite-no-incremental/index.test.ts index 285de2f1..0e5e1612 100644 --- a/test/integration/monorepo-composite-no-incremental/index.test.ts +++ b/test/integration/monorepo-composite-no-incremental/index.test.ts @@ -1,5 +1,5 @@ import { join } from 'path' -import { assertContainFiles, createIntegrationTest } from '../utils' +import { assertContainFiles, createIntegrationTest } from '../../testing-utils' describe('integration monorepo-composite-no-incremental', () => { it('should succeed the build', async () => { diff --git a/test/integration/monorepo-composite/index.test.ts b/test/integration/monorepo-composite/index.test.ts index e280d1f7..10a318b2 100644 --- a/test/integration/monorepo-composite/index.test.ts +++ b/test/integration/monorepo-composite/index.test.ts @@ -1,5 +1,5 @@ import { join } from 'path' -import { assertContainFiles, createIntegrationTest } from '../utils' +import { assertContainFiles, createIntegrationTest } from '../../testing-utils' describe('integration monorepo-composite', () => { it('should succeed the build', async () => { diff --git a/test/integration/multi-entries/index.test.ts b/test/integration/multi-entries/index.test.ts index b6828fb0..8973cff7 100644 --- a/test/integration/multi-entries/index.test.ts +++ b/test/integration/multi-entries/index.test.ts @@ -3,7 +3,7 @@ import { createIntegrationTest, getChunkFileNamesFromLog, stripANSIColor, -} from '../utils' +} from '../../testing-utils' describe('integration multi-entries', () => { it('should contain files', async () => { diff --git a/test/integration/multi-exports-ts/index.test.ts b/test/integration/multi-exports-ts/index.test.ts index 7985c248..60907588 100644 --- a/test/integration/multi-exports-ts/index.test.ts +++ b/test/integration/multi-exports-ts/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegration, assertFilesContent } from '../utils' +import { createIntegration, assertFilesContent } from '../../testing-utils' describe('integration multi-exports', () => { const { dir } = createIntegration({ diff --git a/test/integration/multi-types/index.test.ts b/test/integration/multi-types/index.test.ts index b01370d1..910afd8f 100644 --- a/test/integration/multi-types/index.test.ts +++ b/test/integration/multi-types/index.test.ts @@ -3,7 +3,7 @@ import { createIntegrationTest, getChunkFileNamesFromLog, stripANSIColor, -} from '../utils' +} from '../../testing-utils' describe('integration multi-types', () => { it('should contain files', async () => { diff --git a/test/integration/nested-exports/index.test.ts b/test/integration/nested-exports/index.test.ts index 597103d5..e5b2d49c 100644 --- a/test/integration/nested-exports/index.test.ts +++ b/test/integration/nested-exports/index.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration nested-exports', () => { it('should work with nested path in exports', async () => { diff --git a/test/integration/no-clean/index.test.ts b/test/integration/no-clean/index.test.ts index a19eca19..80222425 100644 --- a/test/integration/no-clean/index.test.ts +++ b/test/integration/no-clean/index.test.ts @@ -5,7 +5,7 @@ import { assertContainFiles, assertFilesContent, createIntegration, -} from '../utils' +} from '../../testing-utils' import { existsSync } from 'fs' describe('integration - no-clean flag', () => { diff --git a/test/integration/node-mixed-legacy-modern-entries/index.test.ts b/test/integration/node-mixed-legacy-modern-entries/index.test.ts index ed7589ec..30fd3321 100644 --- a/test/integration/node-mixed-legacy-modern-entries/index.test.ts +++ b/test/integration/node-mixed-legacy-modern-entries/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertContainFiles } from '../utils' +import { createIntegrationTest, assertContainFiles } from '../../testing-utils' describe('node-mixed-legacy-modern-entries', () => { it('should deduplicate entries', async () => { diff --git a/test/integration/output-short/index.test.ts b/test/integration/output-short/index.test.ts index 0ad9d746..df7b68c2 100644 --- a/test/integration/output-short/index.test.ts +++ b/test/integration/output-short/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, stripANSIColor } from '../utils' +import { createIntegrationTest, stripANSIColor } from '../../testing-utils' const getOutputSizeColumnIndex = (line: string): number => { let match diff --git a/test/integration/output/index.test.ts b/test/integration/output/index.test.ts index faa70cb7..495f7488 100644 --- a/test/integration/output/index.test.ts +++ b/test/integration/output/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, stripANSIColor } from '../utils' +import { createIntegrationTest, stripANSIColor } from '../../testing-utils' const getOutputSizeColumnIndex = (line: string): number => { let match diff --git a/test/integration/pkg-exports-default/index.test.ts b/test/integration/pkg-exports-default/index.test.ts index fdcae4b4..85f0be1a 100644 --- a/test/integration/pkg-exports-default/index.test.ts +++ b/test/integration/pkg-exports-default/index.test.ts @@ -1,6 +1,6 @@ import { promises as fsp } from 'fs' import { join } from 'path' -import { assertContainFiles, createIntegrationTest } from '../utils' +import { assertContainFiles, createIntegrationTest } from '../../testing-utils' describe('integration pkg-exports-default', () => { it('should generate proper assets with js', async () => { diff --git a/test/integration/pkg-exports-js/index.test.ts b/test/integration/pkg-exports-js/index.test.ts index e2926a97..078e4148 100644 --- a/test/integration/pkg-exports-js/index.test.ts +++ b/test/integration/pkg-exports-js/index.test.ts @@ -1,4 +1,4 @@ -import { assertContainFiles, createIntegrationTest } from '../utils' +import { assertContainFiles, createIntegrationTest } from '../../testing-utils' describe('integration pkg-exports-js', () => { it('should generate proper assets with js', async () => { diff --git a/test/integration/pkg-exports-ts-rsc/index.test.ts b/test/integration/pkg-exports-ts-rsc/index.test.ts index ce52556e..3d3e3484 100644 --- a/test/integration/pkg-exports-ts-rsc/index.test.ts +++ b/test/integration/pkg-exports-ts-rsc/index.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration pkg-exports-ts-rsc', () => { it('should generate proper assets for rsc condition with ts', async () => { diff --git a/test/integration/prepare-js/index.test.ts b/test/integration/prepare-js/index.test.ts index 96a8e3e3..133a64c8 100644 --- a/test/integration/prepare-js/index.test.ts +++ b/test/integration/prepare-js/index.test.ts @@ -4,7 +4,7 @@ import { assertContainFiles, createIntegrationTest, stripANSIColor, -} from '../utils' +} from '../../testing-utils' describe('integration prepare-js', () => { const dir = __dirname diff --git a/test/integration/prepare-ts-with-pkg-json/index.test.ts b/test/integration/prepare-ts-with-pkg-json/index.test.ts index 273106e5..885bf98e 100644 --- a/test/integration/prepare-ts-with-pkg-json/index.test.ts +++ b/test/integration/prepare-ts-with-pkg-json/index.test.ts @@ -1,6 +1,10 @@ import fsp from 'fs/promises' import { join } from 'path' -import { assertContainFiles, createIntegrationTest, deleteFile } from '../utils' +import { + assertContainFiles, + createIntegrationTest, + deleteFile, +} from '../../testing-utils' describe('integration prepare-ts-with-pkg-json', () => { const dir = __dirname diff --git a/test/integration/prepare-ts-with-test-file/index.test.ts b/test/integration/prepare-ts-with-test-file/index.test.ts index 55e7ff7c..19841c46 100644 --- a/test/integration/prepare-ts-with-test-file/index.test.ts +++ b/test/integration/prepare-ts-with-test-file/index.test.ts @@ -1,6 +1,10 @@ import fsp from 'fs/promises' import { join } from 'path' -import { assertContainFiles, createIntegrationTest, deleteFile } from '../utils' +import { + assertContainFiles, + createIntegrationTest, + deleteFile, +} from '../../testing-utils' describe('integration prepare-ts-with-test-file', () => { const dir = __dirname diff --git a/test/integration/prepare-ts/index.test.ts b/test/integration/prepare-ts/index.test.ts index 2012bfb0..14a9bffc 100644 --- a/test/integration/prepare-ts/index.test.ts +++ b/test/integration/prepare-ts/index.test.ts @@ -5,7 +5,7 @@ import { createIntegrationTest, deleteFile, stripANSIColor, -} from '../utils' +} from '../../testing-utils' describe('integration prepare-ts', () => { beforeAll(async () => { diff --git a/test/integration/raw-data/index.test.ts b/test/integration/raw-data/index.test.ts index 4ecb60c5..79f83efa 100644 --- a/test/integration/raw-data/index.test.ts +++ b/test/integration/raw-data/index.test.ts @@ -1,5 +1,5 @@ import { existsSync } from 'fs' -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' import { join } from 'path' describe('integration - raw-data', () => { diff --git a/test/integration/relative-entry/relative-entry.test.ts b/test/integration/relative-entry/relative-entry.test.ts index 9e20123e..79980aea 100644 --- a/test/integration/relative-entry/relative-entry.test.ts +++ b/test/integration/relative-entry/relative-entry.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration relative-entry', () => { it('should generate proper assets for each exports', async () => { diff --git a/test/integration/server-components-same-layer/index.test.ts b/test/integration/server-components-same-layer/index.test.ts index 792406d2..8574785a 100644 --- a/test/integration/server-components-same-layer/index.test.ts +++ b/test/integration/server-components-same-layer/index.test.ts @@ -1,6 +1,6 @@ import { promises as fsp } from 'fs' import { join } from 'path' -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' describe('integration server-components-same-layer', () => { it('should generate proper assets for each exports', async () => { diff --git a/test/integration/server-components/index.test.ts b/test/integration/server-components/index.test.ts index 910de2e2..b8d4f578 100644 --- a/test/integration/server-components/index.test.ts +++ b/test/integration/server-components/index.test.ts @@ -1,4 +1,7 @@ -import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' +import { + createIntegrationTest, + getFileNamesFromDirectory, +} from '../../testing-utils' describe('integration server-components', () => { it('should generate proper assets for each exports', async () => { diff --git a/test/integration/shared-any-module/index.test.ts b/test/integration/shared-any-module/index.test.ts index 844b8d16..910636b1 100644 --- a/test/integration/shared-any-module/index.test.ts +++ b/test/integration/shared-any-module/index.test.ts @@ -2,7 +2,7 @@ import { assertFilesContent, createIntegrationTest, getFileNamesFromDirectory, -} from '../utils' +} from '../../testing-utils' describe('integration shared-module', () => { it('should split all shared module into different chunks', async () => { diff --git a/test/integration/shared-entry/index.test.ts b/test/integration/shared-entry/index.test.ts index 6c0f38ee..2a9e7bed 100644 --- a/test/integration/shared-entry/index.test.ts +++ b/test/integration/shared-entry/index.test.ts @@ -1,6 +1,6 @@ import { promises as fsp } from 'fs' import { join } from 'path' -import { assertContainFiles, createIntegrationTest } from '../utils' +import { assertContainFiles, createIntegrationTest } from '../../testing-utils' describe('integration shared-entry', () => { it('should split shared module into one chunk layer', async () => { diff --git a/test/integration/shared-module-ts-esm/index.test.ts b/test/integration/shared-module-ts-esm/index.test.ts index ba281aa7..0938cab4 100644 --- a/test/integration/shared-module-ts-esm/index.test.ts +++ b/test/integration/shared-module-ts-esm/index.test.ts @@ -1,4 +1,7 @@ -import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' +import { + createIntegrationTest, + getFileNamesFromDirectory, +} from '../../testing-utils' describe('integration shared-module-ts-esm', () => { it('should contain correct type file path of shared chunks', async () => { diff --git a/test/integration/shared-module-ts/index.test.ts b/test/integration/shared-module-ts/index.test.ts index 6eb89194..153578aa 100644 --- a/test/integration/shared-module-ts/index.test.ts +++ b/test/integration/shared-module-ts/index.test.ts @@ -1,4 +1,7 @@ -import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' +import { + createIntegrationTest, + getFileNamesFromDirectory, +} from '../../testing-utils' describe('integration shared-module-ts', () => { it('should contain correct type file path of shared chunks', async () => { diff --git a/test/integration/shared-module-with-suffix/shared-module-with-suffix.test.ts b/test/integration/shared-module-with-suffix/shared-module-with-suffix.test.ts index 88e50b4a..941ee31d 100644 --- a/test/integration/shared-module-with-suffix/shared-module-with-suffix.test.ts +++ b/test/integration/shared-module-with-suffix/shared-module-with-suffix.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration - shared-module-with-suffix', () => { it('should alias correctly for the shared module with special suffix', async () => { diff --git a/test/integration/shared-module/index.test.ts b/test/integration/shared-module/index.test.ts index 5be97948..578e1df4 100644 --- a/test/integration/shared-module/index.test.ts +++ b/test/integration/shared-module/index.test.ts @@ -2,7 +2,7 @@ import { assertFilesContent, createIntegrationTest, getFileNamesFromDirectory, -} from '../utils' +} from '../../testing-utils' describe('integration shared-module', () => { it('should split shared module into one chunk layer', async () => { diff --git a/test/integration/stage3-decorator/index.test.ts b/test/integration/stage3-decorator/index.test.ts index 42486f31..24917757 100644 --- a/test/integration/stage3-decorator/index.test.ts +++ b/test/integration/stage3-decorator/index.test.ts @@ -1,5 +1,5 @@ import { assertContainFiles, stripANSIColor } from '../../testing-utils' -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' import * as console from 'node:console' describe('integration stage3-decorator', () => { diff --git a/test/integration/subpath-imports/index.test.ts b/test/integration/subpath-imports/index.test.ts index 55040f32..f9a156bc 100644 --- a/test/integration/subpath-imports/index.test.ts +++ b/test/integration/subpath-imports/index.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration shared-module', () => { it('should split shared module into one chunk layer', async () => { diff --git a/test/integration/ts-allow-js/index.test.ts b/test/integration/ts-allow-js/index.test.ts index b4f6ec0b..835f0bd8 100644 --- a/test/integration/ts-allow-js/index.test.ts +++ b/test/integration/ts-allow-js/index.test.ts @@ -2,7 +2,7 @@ import { assertContainFiles, assertFilesContent, createIntegrationTest, -} from '../utils' +} from '../../testing-utils' describe('integration - ts-allow-js', () => { it('should generate proper assets', async () => { diff --git a/test/integration/ts-dual-package-module/index.test.ts b/test/integration/ts-dual-package-module/index.test.ts index 2125bfee..7ac73922 100644 --- a/test/integration/ts-dual-package-module/index.test.ts +++ b/test/integration/ts-dual-package-module/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertContainFiles } from '../utils' +import { createIntegrationTest, assertContainFiles } from '../../testing-utils' describe('integration ts-dual-package-module', () => { it('should ensure generated assets', async () => { diff --git a/test/integration/ts-dual-package-type-cjs/index.test.ts b/test/integration/ts-dual-package-type-cjs/index.test.ts index f7034ab6..ed014a00 100644 --- a/test/integration/ts-dual-package-type-cjs/index.test.ts +++ b/test/integration/ts-dual-package-type-cjs/index.test.ts @@ -1,4 +1,4 @@ -import { createIntegrationTest, assertContainFiles } from '../utils' +import { createIntegrationTest, assertContainFiles } from '../../testing-utils' describe('integration ts-dual-package-type-cjs', () => { it('should ensure generated assets', async () => { diff --git a/test/integration/ts-error/index.test.ts b/test/integration/ts-error/index.test.ts index 6f56135a..f5be5fc1 100644 --- a/test/integration/ts-error/index.test.ts +++ b/test/integration/ts-error/index.test.ts @@ -1,6 +1,6 @@ import { join } from 'path' import { existsSync } from 'fs' -import { createIntegrationTest } from '../utils' +import { createIntegrationTest } from '../../testing-utils' describe('integration ts-error', () => { it('should error when ts is not properly resolved', async () => { diff --git a/test/integration/ts-exports-multiple-conditions/index.test.ts b/test/integration/ts-exports-multiple-conditions/index.test.ts index a49fc491..860c7646 100644 --- a/test/integration/ts-exports-multiple-conditions/index.test.ts +++ b/test/integration/ts-exports-multiple-conditions/index.test.ts @@ -2,7 +2,7 @@ import { assertContainFiles, createIntegrationTest, assertFilesContent, -} from '../utils' +} from '../../testing-utils' describe('integration - ts-exports-multiple-conditions', () => { it('should generate proper assets', async () => { diff --git a/test/integration/ts-exports-types/index.test.ts b/test/integration/ts-exports-types/index.test.ts index 6fca3450..61216a28 100644 --- a/test/integration/ts-exports-types/index.test.ts +++ b/test/integration/ts-exports-types/index.test.ts @@ -1,4 +1,4 @@ -import { assertContainFiles, createIntegrationTest } from '../utils' +import { assertContainFiles, createIntegrationTest } from '../../testing-utils' describe('integration - ts-exports-types', () => { it('should generate proper assets', async () => { diff --git a/test/integration/ts-import-json-exports-condition/index.test.ts b/test/integration/ts-import-json-exports-condition/index.test.ts index 8ec2ce95..6f2a3331 100644 --- a/test/integration/ts-import-json-exports-condition/index.test.ts +++ b/test/integration/ts-import-json-exports-condition/index.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration - ts-import-json-exports-condition', () => { it('should output correct bundles and types import json with export condition', async () => { diff --git a/test/integration/ts-import-json-exports-string/index.test.ts b/test/integration/ts-import-json-exports-string/index.test.ts index 8ec2ce95..6f2a3331 100644 --- a/test/integration/ts-import-json-exports-string/index.test.ts +++ b/test/integration/ts-import-json-exports-string/index.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration - ts-import-json-exports-condition', () => { it('should output correct bundles and types import json with export condition', async () => { diff --git a/test/integration/ts-incremental-with-buildinfofile/index.test.ts b/test/integration/ts-incremental-with-buildinfofile/index.test.ts index d095bfcd..4189e5c3 100644 --- a/test/integration/ts-incremental-with-buildinfofile/index.test.ts +++ b/test/integration/ts-incremental-with-buildinfofile/index.test.ts @@ -4,7 +4,7 @@ import { assertContainFiles, assertFilesContent, createIntegrationTest, -} from '../utils' +} from '../../testing-utils' describe('integration - ts-incremental-with-buildinfofile', () => { it('should generate proper assets', async () => { diff --git a/test/integration/ts-incremental/index.test.ts b/test/integration/ts-incremental/index.test.ts index 8b580b7c..a4b7ab53 100644 --- a/test/integration/ts-incremental/index.test.ts +++ b/test/integration/ts-incremental/index.test.ts @@ -3,7 +3,7 @@ import { assertContainFiles, assertFilesContent, createIntegrationTest, -} from '../utils' +} from '../../testing-utils' import { join } from 'path' describe('integration - ts-incremental', () => { diff --git a/test/integration/ts-no-emit/index.test.ts b/test/integration/ts-no-emit/index.test.ts index 5aec333a..afd4ce35 100644 --- a/test/integration/ts-no-emit/index.test.ts +++ b/test/integration/ts-no-emit/index.test.ts @@ -2,7 +2,7 @@ import { assertContainFiles, assertFilesContent, createIntegrationTest, -} from '../utils' +} from '../../testing-utils' describe('integration ts-no-emit', () => { it('should succeed the build', async () => { diff --git a/test/integration/tsconfig-override/index.test.ts b/test/integration/tsconfig-override/index.test.ts index 2ebc94a5..5da534e2 100644 --- a/test/integration/tsconfig-override/index.test.ts +++ b/test/integration/tsconfig-override/index.test.ts @@ -1,4 +1,4 @@ -import { assertFilesContent, createIntegrationTest } from '../utils' +import { assertFilesContent, createIntegrationTest } from '../../testing-utils' describe('integration tsconfig-override', () => { it('should use es5 output in build without override', async () => { diff --git a/test/integration/unspecified-types-paths/index.test.ts b/test/integration/unspecified-types-paths/index.test.ts index 19e0f306..1a7c9bf9 100644 --- a/test/integration/unspecified-types-paths/index.test.ts +++ b/test/integration/unspecified-types-paths/index.test.ts @@ -2,7 +2,7 @@ import { assertFilesContent, createIntegrationTest, getFileNamesFromDirectory, -} from '../utils' +} from '../../testing-utils' describe('integration - tsconfig-override', () => { it('should not generate js types paths if not specified', async () => { diff --git a/test/cli/utils.ts b/test/testing-utils/cli.ts similarity index 83% rename from test/cli/utils.ts rename to test/testing-utils/cli.ts index 4a0cac6e..89d59237 100644 --- a/test/cli/utils.ts +++ b/test/testing-utils/cli.ts @@ -1,8 +1,4 @@ -import { - createTest, - executeBunchee, - type ExcuteBuncheeResult, -} from '../testing-utils' +import { createTest, executeBunchee, type ExcuteBuncheeResult } from './shared' export async function createCliTest( { diff --git a/test/utils/debug.ts b/test/testing-utils/debug.ts similarity index 100% rename from test/utils/debug.ts rename to test/testing-utils/debug.ts diff --git a/test/testing-utils.ts b/test/testing-utils/helpers.ts similarity index 51% rename from test/testing-utils.ts rename to test/testing-utils/helpers.ts index c4f1a37a..8c779766 100644 --- a/test/testing-utils.ts +++ b/test/testing-utils/helpers.ts @@ -1,8 +1,13 @@ import fs from 'fs' import fsp from 'fs/promises' import path from 'path' -import * as debug from './utils/debug' -import { fork } from 'child_process' +import * as debug from './debug' + +export type CreateTestResultExtra = { + dir: string + distDir: string + distFile: string +} export function stripANSIColor(str: string) { return str.replace( @@ -24,7 +29,7 @@ export async function existsFile(filePath: string) { } export function assertContainFiles(dir: string, filePaths: string[]) { - const results = [] + const results: string[] = [] for (const filePath of filePaths) { const fullPath = path.resolve(dir, filePath) const existed = fs.existsSync(fullPath) @@ -94,104 +99,3 @@ export async function deleteFile(f: string) { await fsp.unlink(f) } } - -type CreateTestResultExtra = { - dir: string - distDir: string - distFile: string -} -export async function createTest( - { - args, - options, - directory, - abortTimeout, - run, - }: { - args: string[] - options: { env?: NodeJS.ProcessEnv } - directory: string - abortTimeout?: number - run: ( - args: string[], - options: { env?: NodeJS.ProcessEnv }, - processOptions?: { abortTimeout?: number }, - ) => Promise - }, - testFn?: (context: T & CreateTestResultExtra) => void, -) { - const fixturesDir = directory - const distDir = path.join(fixturesDir, './dist') - let distFile = '' - - if (!args.includes('--cwd')) { - args.push('--cwd', fixturesDir) - } - const outputIndex = args.indexOf('-o') - if (outputIndex !== -1) { - distFile = path.join(fixturesDir, args[outputIndex + 1]) - } - - const result = await run(args, options, { abortTimeout }) - const build = { - ...result, - dir: directory, - distDir, - distFile, - } - if (testFn) { - try { - await testFn(build) - } finally { - if (!process.env.TEST_NOT_CLEANUP) { - await removeDirectory(distDir) - } - } - } - return build -} - -export type ExcuteBuncheeResult = { - code: number | null - signal: NodeJS.Signals | null - stdout: string - stderr: string -} - -export async function executeBunchee( - args: string[], - options: { env?: NodeJS.ProcessEnv }, - processOptions?: { abortTimeout?: number }, -): Promise { - debug.log(`Command: bunchee ${args.join(' ')}`) - - const assetPath = process.env.POST_BUILD - ? '../dist/bin/cli.js' - : '../src/bin/index.ts' - - const ps = fork(path.resolve(__dirname, assetPath), args, { - execArgv: ['-r', '@swc-node/register'], - stdio: 'pipe', - env: { SWC_NODE_IGNORE_DYNAMIC: 'true', ...options.env, ...process.env }, - }) - let stderr = '' - let stdout = '' - ps.stdout?.on('data', (chunk) => (stdout += chunk.toString())) - ps.stderr?.on('data', (chunk) => (stderr += chunk.toString())) - - if (typeof processOptions?.abortTimeout === 'number') { - setTimeout(() => { - ps.kill('SIGTERM') - }, processOptions.abortTimeout) - } - - const [code, signal] = await new Promise< - [number | null, NodeJS.Signals | null] - >((resolve) => { - ps.on('close', (code, signal) => resolve([code, signal])) - }) - if (stdout) process.stdout.write(stdout) - if (stderr) process.stderr.write(stderr) - - return { code, stdout, stderr, signal } -} diff --git a/test/integration/utils.ts b/test/testing-utils/index.ts similarity index 92% rename from test/integration/utils.ts rename to test/testing-utils/index.ts index 86523c14..8dd1f3b2 100644 --- a/test/integration/utils.ts +++ b/test/testing-utils/index.ts @@ -1,14 +1,10 @@ import { glob } from 'glob' -import { - createTest, - executeBunchee, - type ExcuteBuncheeResult, -} from '../testing-utils' +import { createTest, executeBunchee, type ExcuteBuncheeResult } from './shared' function normalizePath(filePath: string) { return filePath.replace(/\\/g, '/') } -export * from '../testing-utils' +export * from './helpers' type IntegrationTestOptions = { args?: string[] @@ -17,6 +13,8 @@ type IntegrationTestOptions = { directory: string } +export { createCliTest } from './cli' + export async function createIntegrationTest( { args, options, abortTimeout, directory }: IntegrationTestOptions, testFn?: Parameters>[1], diff --git a/test/testing-utils/shared.ts b/test/testing-utils/shared.ts new file mode 100644 index 00000000..00d40352 --- /dev/null +++ b/test/testing-utils/shared.ts @@ -0,0 +1,100 @@ +import { fork } from 'child_process' +import { CreateTestResultExtra, removeDirectory } from './helpers' +import path from 'path' +import * as debug from './debug' + +export async function createTest( + { + args, + options, + directory, + abortTimeout, + run, + }: { + args: string[] + options: { env?: NodeJS.ProcessEnv } + directory: string + abortTimeout?: number + run: ( + args: string[], + options: { env?: NodeJS.ProcessEnv }, + processOptions?: { abortTimeout?: number }, + ) => Promise + }, + testFn?: (context: T & CreateTestResultExtra) => void, +) { + const fixturesDir = directory + const distDir = path.join(fixturesDir, './dist') + let distFile = '' + + if (!args.includes('--cwd')) { + args.push('--cwd', fixturesDir) + } + const outputIndex = args.indexOf('-o') + if (outputIndex !== -1) { + distFile = path.join(fixturesDir, args[outputIndex + 1]) + } + + const result = await run(args, options, { abortTimeout }) + const build = { + ...result, + dir: directory, + distDir, + distFile, + } + if (testFn) { + try { + await testFn(build) + } finally { + if (!process.env.TEST_NOT_CLEANUP) { + await removeDirectory(distDir) + } + } + } + return build +} + +export type ExcuteBuncheeResult = { + code: number | null + signal: NodeJS.Signals | null + stdout: string + stderr: string +} + +export async function executeBunchee( + args: string[], + options: { env?: NodeJS.ProcessEnv }, + processOptions?: { abortTimeout?: number }, +): Promise { + debug.log(`Command: bunchee ${args.join(' ')}`) + + const assetPath = process.env.POST_BUILD + ? '../../dist/bin/cli.js' + : '../../src/bin/index.ts' + + const ps = fork(path.resolve(__dirname, assetPath), args, { + execArgv: ['-r', '@swc-node/register'], + stdio: 'pipe', + env: { SWC_NODE_IGNORE_DYNAMIC: 'true', ...options.env, ...process.env }, + }) + let stderr = '' + let stdout = '' + ps.stdout?.on('data', (chunk) => (stdout += chunk.toString())) + ps.stderr?.on('data', (chunk) => (stderr += chunk.toString())) + + if (typeof processOptions?.abortTimeout === 'number') { + setTimeout(() => { + ps.kill('SIGTERM') + }, processOptions.abortTimeout) + } + + const [code, signal] = await new Promise< + [number | null, NodeJS.Signals | null] + >((resolve) => { + ps.on('close', (code, signal) => resolve([code, signal])) + }) + if (stdout) process.stdout.write(stdout) + if (stderr) process.stderr.write(stderr) + + return { code, stdout, stderr, signal } +} diff --git a/test/tsconfig.json b/test/tsconfig.json index e597b432..a9d5f2f7 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -7,18 +7,16 @@ "jsx": "preserve", "baseUrl": "..", "paths": { - "bunchee": ["./src/index.ts"] + "bunchee": ["./src/index.ts"], + "testing-utils": ["./test/testing-utils/index.ts"], } }, "include": [ - "./test/**/*.test.ts", - "./test**/*.test.tsx", - // TODO: group those internal utils - "./test/utils/*", - "./test/testing-utils.ts", - "./test/integration/utils.ts", - "./src/**/*.test.ts", - "./src/**/*.test.tsx" + "./**/*.test.ts", + "./**/*.test.tsx", + "./testing-utils", + "../src/**/*.test.ts", + "../src/**/*.test.tsx" ], "references": [{ "path": "../tsconfig.json" }] } diff --git a/tsconfig.json b/tsconfig.json index abf258ae..74f0f882 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,6 @@ "forceConsistentCasingInFileNames": true }, "references": [{ "path": "./test/tsconfig.json" }], - "include": ["src", "*.d.ts", "**/*.json"], + "include": ["src", "**/*.json"], "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"] }