-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
207 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,67 @@ | ||
import fs from 'fs' | ||
import { createCliTest } from '../../testing-utils' | ||
import { createCliJob } from '../../testing-utils' | ||
|
||
describe('cli', () => { | ||
it(`cli basic should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['hello.js', '-o', 'dist/hello.bundle.js'], | ||
}, | ||
({ code, distFile }) => { | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['hello.js', '-o', 'dist/hello.bundle.js'], | ||
}) | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect(code).toBe(0) | ||
}) | ||
|
||
it(`cli format should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['hello.js', '-f', 'cjs', '-o', 'dist/hello.cjs'], | ||
}, | ||
({ code, distFile }) => { | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs.readFileSync(distFile, { encoding: 'utf-8' }).includes('exports.'), | ||
).toBe(true) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['hello.js', '-f', 'cjs', '-o', 'dist/hello.cjs'], | ||
}) | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs.readFileSync(distFile, { encoding: 'utf-8' }).includes('exports.'), | ||
).toBe(true) | ||
expect(code).toBe(0) | ||
}) | ||
|
||
it(`cli compress should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['hello.js', '-m', '-o', 'dist/hello.bundle.min.js'], | ||
}, | ||
({ code, distFile }) => { | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs.readFileSync(distFile, { encoding: 'utf-8' }).includes('sayHello'), | ||
).toBe(false) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['hello.js', '-m', '-o', 'dist/hello.bundle.min.js'], | ||
}) | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs.readFileSync(distFile, { encoding: 'utf-8' }).includes('sayHello'), | ||
).toBe(false) | ||
expect(code).toBe(0) | ||
}) | ||
|
||
it(`cli sourcemap should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['hello.js', '--sourcemap', '-o', 'dist/hello.js'], | ||
}, | ||
({ code, distFile }) => { | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs | ||
.readFileSync(distFile, { encoding: 'utf-8' }) | ||
.includes('sourceMappingURL'), | ||
).toBe(true) | ||
expect(fs.existsSync(distFile + '.map')).toBe(true) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['hello.js', '--sourcemap', '-o', 'dist/hello.js'], | ||
}) | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs | ||
.readFileSync(distFile, { encoding: 'utf-8' }) | ||
.includes('sourceMappingURL'), | ||
).toBe(true) | ||
expect(fs.existsSync(distFile + '.map')).toBe(true) | ||
expect(code).toBe(0) | ||
}) | ||
|
||
it(`cli minified with sourcemap should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['hello.js', '-m', '--sourcemap', '-o', 'dist/hello.js'], | ||
}, | ||
({ code, distFile }) => { | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs | ||
.readFileSync(distFile, { encoding: 'utf-8' }) | ||
.includes('sourceMappingURL'), | ||
).toBe(true) | ||
expect(fs.existsSync(distFile + '.map')).toBe(true) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['hello.js', '-m', '--sourcemap', '-o', 'dist/hello.js'], | ||
}) | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect( | ||
fs | ||
.readFileSync(distFile, { encoding: 'utf-8' }) | ||
.includes('sourceMappingURL'), | ||
).toBe(true) | ||
expect(fs.existsSync(distFile + '.map')).toBe(true) | ||
expect(code).toBe(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
import fs from 'fs' | ||
import { createCliTest } from '../../testing-utils' | ||
import { createCliJob } from '../../testing-utils' | ||
|
||
describe('cli', () => { | ||
it(`cli cjs-relative-imports should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['index.js', '-o', 'dist/index.js'], | ||
}, | ||
({ code, distFile }) => { | ||
expect(code).toBe(0) | ||
test(`cli cjs-relative-imports should work properly`, async () => { | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['index.js', '-o', 'dist/index.js'], | ||
}) | ||
expect(code).toBe(0) | ||
|
||
const content = fs.readFileSync(distFile, { encoding: 'utf-8' }) | ||
const content = fs.readFileSync(distFile, { encoding: 'utf-8' }) | ||
|
||
expect(content.includes('dot-js-dep')).toBe(true) | ||
expect(content.includes('dot-cjs-dep')).toBe(true) | ||
}, | ||
) | ||
}) | ||
expect(content.includes('dot-js-dep')).toBe(true) | ||
expect(content.includes('dot-cjs-dep')).toBe(true) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { createCliTest } from '../../testing-utils' | ||
import { createCliJob } from '../../testing-utils' | ||
|
||
describe('cli', () => { | ||
it(`cli dts should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['./input.ts', '-o', 'dist/output.js'], | ||
}, | ||
({ code, distFile }) => { | ||
const typeFile = distFile.replace('.js', '.d.ts') | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['./input.ts', '-o', 'dist/output.js'], | ||
}) | ||
const typeFile = distFile.replace('.js', '.d.ts') | ||
|
||
expect(path.basename(distFile)).toBe('output.js') | ||
expect(path.basename(typeFile)).toBe('output.d.ts') | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect(fs.existsSync(typeFile)).toBe(true) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
expect(path.basename(distFile)).toBe('output.js') | ||
expect(path.basename(typeFile)).toBe('output.d.ts') | ||
expect(fs.existsSync(distFile)).toBe(true) | ||
expect(fs.existsSync(typeFile)).toBe(true) | ||
expect(code).toBe(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
import fs from 'fs' | ||
import { createCliTest } from '../../testing-utils' | ||
import { createCliJob } from '../../testing-utils' | ||
|
||
describe('cli', () => { | ||
it(`cli env-var should work properly`, async () => { | ||
await createCliTest( | ||
{ | ||
directory: __dirname, | ||
args: ['index.js', '--env', 'MY_TEST_ENV', '-o', 'dist/index.js'], | ||
options: { | ||
env: { | ||
MY_TEST_ENV: 'my-test-value', | ||
}, | ||
}, | ||
test(`cli env-var should work properly`, async () => { | ||
const { code, distFile } = await createCliJob({ | ||
directory: __dirname, | ||
args: ['index.js', '--env', 'MY_TEST_ENV', '-o', 'dist/index.js'], | ||
options: { | ||
env: { | ||
MY_TEST_ENV: 'my-test-value', | ||
}, | ||
({ code, distFile }) => { | ||
const content = fs.readFileSync(distFile, { encoding: 'utf-8' }) | ||
expect(content.includes('my-test-value')).toBe(true) | ||
expect(code).toBe(0) | ||
}, | ||
) | ||
}, | ||
}) | ||
const content = fs.readFileSync(distFile, { encoding: 'utf-8' }) | ||
expect(content.includes('my-test-value')).toBe(true) | ||
expect(code).toBe(0) | ||
}) |
Oops, something went wrong.