Skip to content
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

test: improve testing utils #629

Merged
merged 4 commits into from
Jan 11, 2025
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
"node_modules"
],
"moduleNameMapper": {
"^bunchee$": "<rootDir>/src/index.ts",
"^testing-utils$": "<rootDir>/test/integration/utils.ts"
"^bunchee$": "<rootDir>/src/index.ts"
},
"transform": {
"^.+\\.(t|j)sx?$": [
Expand Down
2 changes: 1 addition & 1 deletion test/typing.test.ts → src/typing.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/cli/basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/cjs-relative-imports/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
3 changes: 1 addition & 2 deletions test/cli/dts-bundle/index.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/cli/dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/env-var/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/externals/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/no-dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/no-entry/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createCliTest } from '../utils'
import { createCliTest } from '../../testing-utils'

describe('cli', () => {
it(`cli no-entry should work properly`, async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/output-in-watch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createCliTest } from '../utils'
import { createCliTest } from '../../testing-utils'

describe('cli', () => {
it(`cli output-in-watch should work properly`, async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/target/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/workspace/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { createCliTest } from '../utils'
import { createCliTest } from '../../testing-utils'
import path from 'path'

describe('cli', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/integration-test-template/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIntegrationTest, assertContainFiles } from 'testing-utils'
import { createIntegrationTest, assertContainFiles } from '../../testing-utils'

describe('integration - <name>', () => {
it('should work', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/basic-jsx/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
5 changes: 4 additions & 1 deletion test/integration/bin/cts/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/bin/multi-path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/bin/patch-binary/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createIntegrationTest,
assertContainFiles,
assertFilesContent,
} from '../../utils'
} from '../../../testing-utils'

describe('integration bin/patch-binary', () => {
it('should patch binary directive', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/bin/single-path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/browserslist/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/conflicted-entry/conflicted-entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIntegrationTest } from '../utils'
import { createIntegrationTest } from '../../testing-utils'

describe('integration - conflicted-entry', () => {
it('should error on conflicted entries', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/default-node-mjs/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dev-prod-convention/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dev-prod-nested-convention/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dev-prod-special-convention/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
5 changes: 4 additions & 1 deletion test/integration/dynamic-require/dynamic-require.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/edge-variable/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/entry-index-index/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/esm-pkg-cjs-main-field/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/esm-shims/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createIntegrationTest,
assertFilesContent,
getFileContents,
} from '../utils'
} from '../../testing-utils'

describe('integration esm-shims', () => {
it('should work with ESM shims', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/externals/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/import-fallback/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/js-bad-configured-types/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/js-only/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIntegrationTest, existsFile } from '../utils'
import { createIntegrationTest, existsFile } from '../../testing-utils'

describe('integration js-only', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/lint/cjs-pkg-esm-main-field/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/lint/invalid-exports-cjs/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/lint/invalid-exports-esm/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/lint/missing-files-exports/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/lint/missing-files-main/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/lint/single-entry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
5 changes: 4 additions & 1 deletion test/integration/mixed-directives/mixed-directives.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/monorepo-composite/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/multi-entries/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createIntegrationTest,
getChunkFileNamesFromLog,
stripANSIColor,
} from '../utils'
} from '../../testing-utils'

describe('integration multi-entries', () => {
it('should contain files', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/multi-exports-ts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIntegration, assertFilesContent } from '../utils'
import { createIntegration, assertFilesContent } from '../../testing-utils'

describe('integration multi-exports', () => {
const { dir } = createIntegration({
Expand Down
2 changes: 1 addition & 1 deletion test/integration/multi-types/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createIntegrationTest,
getChunkFileNamesFromLog,
stripANSIColor,
} from '../utils'
} from '../../testing-utils'

describe('integration multi-types', () => {
it('should contain files', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/nested-exports/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/no-clean/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
assertContainFiles,
assertFilesContent,
createIntegration,
} from '../utils'
} from '../../testing-utils'
import { existsSync } from 'fs'

describe('integration - no-clean flag', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/output-short/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIntegrationTest, stripANSIColor } from '../utils'
import { createIntegrationTest, stripANSIColor } from '../../testing-utils'

const getOutputSizeColumnIndex = (line: string): number => {
let match
Expand Down
2 changes: 1 addition & 1 deletion test/integration/output/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIntegrationTest, stripANSIColor } from '../utils'
import { createIntegrationTest, stripANSIColor } from '../../testing-utils'

const getOutputSizeColumnIndex = (line: string): number => {
let match
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pkg-exports-default/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pkg-exports-js/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pkg-exports-ts-rsc/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Loading
Loading