From adcf5be9e671c8e4e4307490c8dbc48b9058670e Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Thu, 13 Feb 2020 21:19:12 +1300 Subject: [PATCH] test: Utility to extened pre-prepared fixtures --- tests/fixtures/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/index.js b/tests/fixtures/index.js index 37f255725..2f195cc0e 100644 --- a/tests/fixtures/index.js +++ b/tests/fixtures/index.js @@ -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 => {