From b994ffe82f407bbf0adf50fc6eceff602fa48cd4 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 11:19:35 +0100 Subject: [PATCH] make sure the integration set suite works cross-platform (not depedent on gnu sed) --- tests/integration/simple-integration-test.js | 4 ++-- tests/utils/index.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/integration/simple-integration-test.js b/tests/integration/simple-integration-test.js index 40c990119..2fab3d6b3 100644 --- a/tests/integration/simple-integration-test.js +++ b/tests/integration/simple-integration-test.js @@ -29,8 +29,8 @@ describe('Service Lifecyle Integration Test', function () { it('should create service in tmp directory', () => { execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); - execSync(`sed -i.bak s/${templateName}/${newServiceName}/g serverless.yml`); - execSync("sed -i.bak '/provider:/a \\ cfLogs: true' serverless.yml"); + testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); + testUtils.replaceTextInFile('serverless.yml', 'name: aws', 'name: aws\n cfLogs: true'); expect(serverless.utils .fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); expect(serverless.utils diff --git a/tests/utils/index.js b/tests/utils/index.js index b3195db4e..af257ae7e 100644 --- a/tests/utils/index.js +++ b/tests/utils/index.js @@ -1,5 +1,6 @@ 'use strict'; +const fs = require('fs'); const os = require('os'); const path = require('path'); const crypto = require('crypto'); @@ -18,10 +19,16 @@ const getTmpDirPath = () => path.join(os.tmpdir(), const getTmpFilePath = (fileName) => path.join(getTmpDirPath(), fileName); +const replaceTextInFile = (filePath, subString, newSubString) => { + const fileContent = fs.readFileSync(filePath).toString(); + fs.writeFileSync(filePath, fileContent.replace(subString, newSubString)); +}; + module.exports = { serverlessExec, getTmpDirPath, getTmpFilePath, + replaceTextInFile, createTestService: (templateName, testServiceDir) => { const serviceName = `service-${(new Date()).getTime().toString()}`; @@ -40,6 +47,7 @@ module.exports = { fse.copySync(testServiceDir, tmpDir, { clobber: true, preserveTimestamps: true }); } + replaceTextInFile('serverless.yml', templateName, serviceName); execSync(`sed -i.bak s/${templateName}/${serviceName}/g serverless.yml`); process.env.TOPIC_1 = `${serviceName}-1`;