-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle case where cwd is set to dir created with mkdir (#25)
- Loading branch information
Showing
4 changed files
with
60 additions
and
7 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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
import { Joker } from '.'; | ||
|
||
function mkdirTmpDir() { | ||
const tmpDir = path.join( | ||
os.tmpdir(), | ||
String(Math.floor(Math.random() * 100)) | ||
); | ||
if (fs.existsSync(tmpDir)) { | ||
fs.rmdirSync(tmpDir); | ||
} | ||
return tmpDir; | ||
} | ||
|
||
describe('Joker#cwd', () => { | ||
it('should accept given path', async () => { | ||
const tmpDir = mkdirTmpDir(); | ||
await new Joker() | ||
.cwd(tmpDir) | ||
.run('echo foo') | ||
.end(); | ||
}); | ||
|
||
it('should change allow changing cwd to created dir', async () => { | ||
const tmpDir = mkdirTmpDir(); | ||
await new Joker() | ||
.mkdir(tmpDir) | ||
.cwd(tmpDir) | ||
.run('echo foo') | ||
.rmdir(tmpDir) | ||
.end(); | ||
expect(fs.existsSync(tmpDir)).toBe(false); | ||
}); | ||
|
||
it('should fail if given path does not exist', async () => { | ||
await expect( | ||
new Joker() | ||
.cwd('non_existent_path') | ||
.run('echo foo') | ||
.end() | ||
).rejects.toThrow('The path "non_existent_path" does not exist'); | ||
}); | ||
}); |