mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
test: Utility to extened pre-prepared fixtures
This commit is contained in:
parent
dfeca8e622
commit
adcf5be9e6
23
tests/fixtures/index.js
vendored
23
tests/fixtures/index.js
vendored
@ -3,7 +3,9 @@
|
||||
const path = require('path');
|
||||
const BbPromise = require('bluebird');
|
||||
const fse = BbPromise.promisifyAll(require('fs-extra'));
|
||||
const { memoize } = require('lodash');
|
||||
const { memoize, merge } = require('lodash');
|
||||
const { load: loadYaml, dump: saveYaml } = require('js-yaml');
|
||||
const provisionTmpDir = require('@serverless/test/provision-tmp-dir');
|
||||
|
||||
const isFixtureConfigured = memoize(fixturePath => {
|
||||
let stats;
|
||||
@ -32,6 +34,25 @@ module.exports = {
|
||||
},
|
||||
}
|
||||
),
|
||||
extend: (fixtureName, extConfig) => {
|
||||
const baseFixturePath = path.join(__dirname, fixtureName);
|
||||
if (!isFixtureConfigured(baseFixturePath)) {
|
||||
throw new Error(`No fixture configured at ${fixtureName}`);
|
||||
}
|
||||
return provisionTmpDir().then(fixturePath => {
|
||||
return Promise.all([
|
||||
fse.readFileAsync(path.join(baseFixturePath, 'serverless.yml')),
|
||||
fse.copyAsync(baseFixturePath, fixturePath),
|
||||
])
|
||||
.then(([yamlConfig]) =>
|
||||
fse.writeFileAsync(
|
||||
path.join(fixturePath, 'serverless.yml'),
|
||||
saveYaml(merge(loadYaml(yamlConfig), extConfig))
|
||||
)
|
||||
)
|
||||
.then(() => fixturePath);
|
||||
});
|
||||
},
|
||||
cleanup: (options = {}) =>
|
||||
Promise.all(
|
||||
Array.from(retrievedFixturesPaths, fixturePath => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user