|
1 | 1 | import {resolve} from 'path'
|
2 |
| -import {getBabelArgs, getTypescriptArgs} from '../utils' |
| 2 | +import { |
| 3 | + getBabelArgs, |
| 4 | + getTypescriptArgs, |
| 5 | + getCopiedFilesToDelete, |
| 6 | +} from '../utils' |
3 | 7 | import {BUILD_ARGS} from '../../../cli/args'
|
4 | 8 | import {ModuleFormat} from '../../types'
|
5 | 9 | import BASE_TSCONFIG from '../../test/tsconfig.json'
|
6 | 10 |
|
7 | 11 | const CWD = process.cwd()
|
8 | 12 |
|
9 | 13 | describe('getBabelArgs', () => {
|
| 14 | + describe('source files', () => { |
| 15 | + it('uses current working directory for source files location', () => { |
| 16 | + const [firstSetOfArgs] = getBabelArgs({ |
| 17 | + formats: BUILD_ARGS.formats.default, |
| 18 | + out: BUILD_ARGS.out.default, |
| 19 | + watch: BUILD_ARGS.watch.default, |
| 20 | + }) |
| 21 | + |
| 22 | + expect(firstSetOfArgs.cliOptions.filenames).toEqual([resolve(CWD, 'src')]) |
| 23 | + }) |
| 24 | + }) |
| 25 | + |
10 | 26 | describe('formats + out', () => {
|
11 | 27 | it('returns empty array when empty formats are specified', () => {
|
12 | 28 | const babelArgsToRun = getBabelArgs({
|
@@ -195,14 +211,34 @@ describe('getTypescriptArgs', () => {
|
195 | 211 | })
|
196 | 212 | })
|
197 | 213 |
|
198 |
| - it('uses current working director for source files location', () => { |
199 |
| - const typescriptArgs = getTypescriptArgs({ |
200 |
| - formats: new Set(['type'] as ModuleFormat[]), |
201 |
| - out: BUILD_ARGS.out.default, |
202 |
| - watch: BUILD_ARGS.watch.default, |
| 214 | + describe('source files', () => { |
| 215 | + it('uses current working directory for source files location', () => { |
| 216 | + const typescriptArgs = getTypescriptArgs({ |
| 217 | + formats: new Set(['type'] as ModuleFormat[]), |
| 218 | + out: BUILD_ARGS.out.default, |
| 219 | + watch: BUILD_ARGS.watch.default, |
| 220 | + }) |
| 221 | + |
| 222 | + expect(typescriptArgs).toContain(resolve(CWD, 'src/*.ts')) |
203 | 223 | })
|
| 224 | + }) |
| 225 | + }) |
| 226 | +}) |
| 227 | + |
| 228 | +describe('getCopiedFilesToDelete', () => { |
| 229 | + it('prepends the passed in output path to the glob patterns (when relative)', () => { |
| 230 | + const files = getCopiedFilesToDelete('./built') |
| 231 | + |
| 232 | + files.forEach((globPattern) => { |
| 233 | + expect(globPattern).toMatch(new RegExp(`^${resolve(CWD, 'built')}/`)) |
| 234 | + }) |
| 235 | + }) |
| 236 | + |
| 237 | + it('prepends the passed in output path to the glob patterns (when absolute)', () => { |
| 238 | + const files = getCopiedFilesToDelete('/path/to/built') |
204 | 239 |
|
205 |
| - expect(typescriptArgs).toContain(resolve(CWD, 'src/*.ts')) |
| 240 | + files.forEach((globPattern) => { |
| 241 | + expect(globPattern).toMatch(new RegExp('/path/to/built/')) |
206 | 242 | })
|
207 | 243 | })
|
208 | 244 | })
|
0 commit comments