-
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.
- Loading branch information
Deepak Dahal
committed
May 18, 2017
1 parent
ecec8a0
commit db219de
Showing
1 changed file
with
56 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import path from 'path'; | ||
import { spawn } from 'child_process'; | ||
import sinon from 'sinon'; | ||
|
||
const TEST_CACHE_PATH = 'test/sandbox/test-cache'; | ||
|
||
global.chai = chai; | ||
|
||
global.chai.use(chaiAsPromised); | ||
|
||
global.sinon = sinon; | ||
|
||
global.execAsPromise = (command, args) => { | ||
return new Promise((resolve, reject) => { | ||
let | ||
message = [], | ||
process = spawn(command, args); | ||
|
||
process.stderr.on('data', (buffer) => message.push(buffer.toString())); | ||
|
||
process.on('close', (code) => { | ||
if (code !== 0) { | ||
return reject(new Error(message.join(''))); | ||
} | ||
|
||
return resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
global.prepareTestCacheAsDirectory = () => { | ||
return global.execAsPromise('mkdir', ['-p', TEST_CACHE_PATH]); | ||
}; | ||
|
||
global.prepareTestCacheAsFile = () => { | ||
return global.execAsPromise('touch', [TEST_CACHE_PATH]); | ||
}; | ||
|
||
global.prepareTestCacheFile = (filename) => { | ||
return global.execAsPromise('touch', [path.join(TEST_CACHE_PATH, filename)]); | ||
}; | ||
|
||
global.prepareTestCacheAsSymbolicLink = () => { | ||
return global.execAsPromise('ln', ['-s', '.', TEST_CACHE_PATH]); | ||
}; | ||
|
||
global.removeTestCache = () => { | ||
return global.execAsPromise('rm', ['-rf', TEST_CACHE_PATH]); | ||
}; | ||
|
||
global.should = chai.should(); | ||
|
||
global.TEST_CACHE_PATH = TEST_CACHE_PATH; | ||
|