-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
1 parent
cad40b4
commit 3f61979
Showing
2 changed files
with
46 additions
and
22 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,34 +1,52 @@ | ||
import { getSpawnOpts } from './spawn'; | ||
import { getSpawnOpts, spawn } from './spawn'; | ||
|
||
const baseProcess = { | ||
platform: 'win32' as const, | ||
cwd: () => '', | ||
env: {}, | ||
}; | ||
|
||
it('sets detached mode to false for Windows platform', () => { | ||
expect(getSpawnOpts({ process: baseProcess }).detached).toBe(false); | ||
}); | ||
describe('spawn()', () => { | ||
it('spawns the given command', async () => { | ||
const fakeSpawn = jest.fn(); | ||
spawn('echo banana', {}, fakeSpawn, baseProcess); | ||
expect(fakeSpawn).toHaveBeenCalled(); | ||
expect(fakeSpawn.mock.calls[0][1].join(' ')).toContain('echo banana'); | ||
}); | ||
|
||
it('sets stdio to inherit when raw', () => { | ||
expect(getSpawnOpts({ raw: true }).stdio).toBe('inherit'); | ||
it('returns spawned process', async () => { | ||
const childProcess = {}; | ||
const fakeSpawn = jest.fn().mockReturnValue(childProcess); | ||
const child = spawn('echo banana', {}, fakeSpawn, baseProcess); | ||
expect(child).toBe(childProcess); | ||
}); | ||
}); | ||
|
||
it('merges FORCE_COLOR into env vars if color supported', () => { | ||
const process = { ...baseProcess, env: { foo: 'bar' } }; | ||
expect(getSpawnOpts({ process, colorSupport: false }).env).toEqual(process.env); | ||
expect(getSpawnOpts({ process, colorSupport: { level: 1 } }).env).toEqual({ | ||
FORCE_COLOR: '1', | ||
foo: 'bar', | ||
describe('getSpawnOpts()', () => { | ||
it('sets detached mode to false for Windows platform', () => { | ||
expect(getSpawnOpts({ process: baseProcess }).detached).toBe(false); | ||
}); | ||
}); | ||
|
||
it('sets default cwd to process.cwd()', () => { | ||
const process = { ...baseProcess, cwd: () => 'process-cwd' }; | ||
expect(getSpawnOpts({ process }).cwd).toBe('process-cwd'); | ||
}); | ||
it('sets stdio to inherit when raw', () => { | ||
expect(getSpawnOpts({ raw: true }).stdio).toBe('inherit'); | ||
}); | ||
|
||
it('overrides default cwd', () => { | ||
const cwd = 'foobar'; | ||
expect(getSpawnOpts({ cwd }).cwd).toBe(cwd); | ||
it('merges FORCE_COLOR into env vars if color supported', () => { | ||
const process = { ...baseProcess, env: { foo: 'bar' } }; | ||
expect(getSpawnOpts({ process, colorSupport: false }).env).toEqual(process.env); | ||
expect(getSpawnOpts({ process, colorSupport: { level: 1 } }).env).toEqual({ | ||
FORCE_COLOR: '1', | ||
foo: 'bar', | ||
}); | ||
}); | ||
|
||
it('sets default cwd to process.cwd()', () => { | ||
const process = { ...baseProcess, cwd: () => 'process-cwd' }; | ||
expect(getSpawnOpts({ process }).cwd).toBe('process-cwd'); | ||
}); | ||
|
||
it('overrides default cwd', () => { | ||
const cwd = 'foobar'; | ||
expect(getSpawnOpts({ cwd }).cwd).toBe(cwd); | ||
}); | ||
}); |
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