make sure the integration set suite works cross-platform (not depedent on gnu sed)

This commit is contained in:
Nik Graf 2016-12-16 11:19:35 +01:00
parent e6d838dceb
commit b994ffe82f
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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`;