Skip to content

Commit

Permalink
test: migrate all int test to new util (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Jan 12, 2025
1 parent 8633425 commit 92607fa
Show file tree
Hide file tree
Showing 82 changed files with 853 additions and 1,247 deletions.
12 changes: 6 additions & 6 deletions test/cli/basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

describe('cli', () => {
it(`cli basic should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['hello.js', '-o', 'dist/hello.bundle.js'],
})
Expand All @@ -12,7 +12,7 @@ describe('cli', () => {
})

it(`cli format should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['hello.js', '-f', 'cjs', '-o', 'dist/hello.cjs'],
})
Expand All @@ -24,7 +24,7 @@ describe('cli', () => {
})

it(`cli compress should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['hello.js', '-m', '-o', 'dist/hello.bundle.min.js'],
})
Expand All @@ -36,7 +36,7 @@ describe('cli', () => {
})

it(`cli sourcemap should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['hello.js', '--sourcemap', '-o', 'dist/hello.js'],
})
Expand All @@ -51,7 +51,7 @@ describe('cli', () => {
})

it(`cli minified with sourcemap should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['hello.js', '-m', '--sourcemap', '-o', 'dist/hello.js'],
})
Expand Down
4 changes: 2 additions & 2 deletions test/cli/cjs-relative-imports/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

test(`cli cjs-relative-imports should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['index.js', '-o', 'dist/index.js'],
})
Expand Down
8 changes: 4 additions & 4 deletions test/cli/dts-bundle/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import fsp from 'fs/promises'
import { join } from 'path'
import { createCliJob, deleteFile } from '../../testing-utils'
import { runCli, deleteFile } from '../../testing-utils'

describe('cli', () => {
const dir = __dirname
Expand All @@ -16,7 +16,7 @@ describe('cli', () => {
})

it(`cli dts-bundle option should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['./base.ts', '-o', 'dist/base.js', '--dts-bundle'],
})
Expand All @@ -27,7 +27,7 @@ describe('cli', () => {
})

it(`cli dts-bundle option should not bundle dts without dts-bundle`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['./base.ts', '-o', 'dist/base.js'],
})
Expand All @@ -42,7 +42,7 @@ describe('cli', () => {
join(dir, './package.json'),
'{ "name": "prepare-ts-with-pkg-json", "dependencies": { "@swc/types": "*" } }',
)
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['./base.ts', '-o', 'dist/base.js'],
})
Expand Down
4 changes: 2 additions & 2 deletions test/cli/dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs'
import path from 'path'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

describe('cli', () => {
it(`cli dts should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['./input.ts', '-o', 'dist/output.js'],
})
Expand Down
4 changes: 2 additions & 2 deletions test/cli/env-var/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

test(`cli env-var should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['index.js', '--env', 'MY_TEST_ENV', '-o', 'dist/index.js'],
options: {
Expand Down
6 changes: 3 additions & 3 deletions test/cli/externals/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

describe('cli', () => {
it(`cli external should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: [
'with-externals.js',
Expand All @@ -21,7 +21,7 @@ describe('cli', () => {
})

it(`cli no-externals should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: [
'with-externals.js',
Expand Down
4 changes: 2 additions & 2 deletions test/cli/no-dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs'
import path from 'path'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

test(`cli no-dts option should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['./base.ts', '-o', 'dist/base.js', '--no-dts'],
})
Expand Down
4 changes: 2 additions & 2 deletions test/cli/no-entry/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

test(`cli no-entry should work properly`, async () => {
const { code, stderr } = await createCliJob({
const { code, stderr } = await runCli({
directory: __dirname,
})
expect(
Expand Down
4 changes: 2 additions & 2 deletions test/cli/output-in-watch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

test('cli - output-in-watch', async () => {
const { stdout, signal } = await createCliJob({
const { stdout, signal } = await runCli({
directory: __dirname,
args: ['hello.js', '-w', '-o', 'dist/hello.bundle.js'],
abortTimeout: 3000,
Expand Down
4 changes: 2 additions & 2 deletions test/cli/target/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'

test(`cli es2020-target should work properly`, async () => {
const { code, distFile } = await createCliJob({
const { code, distFile } = await runCli({
directory: __dirname,
args: ['es2020.ts', '--target', 'es2020', '-o', 'dist/es2020.js'],
})
Expand Down
4 changes: 2 additions & 2 deletions test/cli/workspace/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs'
import { createCliJob } from '../../testing-utils'
import { runCli } from '../../testing-utils'
import path from 'path'

describe('cli', () => {
it(`cli workspace should work properly`, async () => {
const { code, distDir } = await createCliJob({
const { code, distDir } = await runCli({
directory: __dirname,
args: ['./index.ts'],
})
Expand Down
21 changes: 7 additions & 14 deletions test/integration/bin/cts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {
assertFilesContent,
createIntegrationTest,
} from '../../../testing-utils'
import { assertFilesContent, createJob } from '../../../testing-utils'

describe('integration bin/cts', () => {
const { distDir } = createJob({
directory: __dirname,
})
it('should work with bin as .cts extension', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ distDir }) => {
await assertFilesContent(distDir, {
'bin/index.cjs': '#!/usr/bin/env node',
})
},
)
await assertFilesContent(distDir, {
'bin/index.cjs': '#!/usr/bin/env node',
})
})
})
20 changes: 8 additions & 12 deletions test/integration/bin/multi-path/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
assertFilesContent,
createIntegrationTest,
createJob,
isWindows,
} from '../../../testing-utils'

Expand All @@ -10,17 +10,13 @@ describe('integration bin/multi-path', () => {
it('skip test on windows', () => {})
return
}
const { distDir } = createJob({
directory: __dirname,
})
it('should work with bin as multi path', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ distDir }) => {
await assertFilesContent(distDir, {
'bin/a.js': '#!/usr/bin/env node',
'bin/b.js': '#!/usr/bin/env node',
})
},
)
await assertFilesContent(distDir, {
'bin/a.js': '#!/usr/bin/env node',
'bin/b.js': '#!/usr/bin/env node',
})
})
})
20 changes: 7 additions & 13 deletions test/integration/bin/patch-binary/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import {
createIntegrationTest,
assertContainFiles,
assertFilesContent,
createJob,
} from '../../../testing-utils'

describe('integration bin/patch-binary', () => {
const { distDir } = createJob({ directory: __dirname })
it('should patch binary directive', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ distDir }) => {
const distFiles = ['bin.js']
await assertContainFiles(distDir, distFiles)
await assertFilesContent(distDir, {
'bin.js': "#!/usr/bin/env node\nconsole.log('Hello, world!');",
})
},
)
const distFiles = ['bin.js']
await assertContainFiles(distDir, distFiles)
await assertFilesContent(distDir, {
'bin.js': "#!/usr/bin/env node\nconsole.log('Hello, world!');",
})
})
})
25 changes: 7 additions & 18 deletions test/integration/bin/single-path/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
createIntegrationTest,
createJob,
assertContainFiles,
assertFilesContent,
getFileNamesFromDirectory,
isWindows,
} from '../../../testing-utils'

Expand All @@ -12,22 +11,12 @@ describe('integration bin/single-path', () => {
it('skip test on windows', () => {})
return
}
const { distDir } = createJob({ directory: __dirname })
it('should work with bin as single path', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ distDir }) => {
console.log(
'getFileNamesFromDirectory',
getFileNamesFromDirectory(distDir),
)
const distFiles = ['bin.js']
await assertContainFiles(distDir, distFiles)
await assertFilesContent(distDir, {
'bin.js': /console.log\('Hello, world!'\)/,
})
},
)
const distFiles = ['bin.js']
await assertContainFiles(distDir, distFiles)
await assertFilesContent(distDir, {
'bin.js': /console.log\('Hello, world!'\)/,
})
})
})
16 changes: 5 additions & 11 deletions test/integration/browserslist/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { createIntegrationTest, assertFilesContent } from '../../testing-utils'
import { assertFilesContent, createJob } from '../../testing-utils'

describe('browserslist', () => {
const { distDir } = createJob({ directory: __dirname })
it('should work with basic JSX format', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
({ distDir }) => {
assertFilesContent(distDir, {
'index.js': `_class_private_field_loose_key`,
})
},
)
await assertFilesContent(distDir, {
'index.js': `_class_private_field_loose_key`,
})
})
})
17 changes: 5 additions & 12 deletions test/integration/conflicted-entry/conflicted-entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { createIntegrationTest } from '../../testing-utils'
import { createJob } from '../../testing-utils'

describe('integration - conflicted-entry', () => {
const { job } = createJob({ directory: __dirname })
it('should error on conflicted entries', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ code, stderr }) => {
expect(code).toBe(1)
expect(stderr).toContain(
'Conflicted entry files found for entries: ./foo',
)
},
)
const { code, stderr } = job
expect(code).toBe(1)
expect(stderr).toContain('Conflicted entry files found for entries: ./foo')
})
})
Loading

0 comments on commit 92607fa

Please sign in to comment.