All files / src/serverless/deploy-multiple rollback.js

100% Statements 13/13
100% Branches 2/2
100% Functions 3/3
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27    1x 1x 1x   1x 1x 2x   2x   2x   2x 1x   1x       1x       1x  
'use strict';
 
const Sls = require('../command');
const { CanNotRollback } = require('../../common/errors');
const { wrap } = require('../../utils/child-process');
 
const versionRegExp = /Serverless: Timestamp: (\d+)/;
const rollback = ({ path, logStream, stdout }) => {
    const sls = new Sls(path, '');
 
    return wrap(sls.rollback(), { stdout })
        .then(log => {
            const match = log.match(versionRegExp);
 
            if (match) {
                return versionRegExp.exec(match[0])[1];
            } else {
                return Promise.reject(new CanNotRollback());
            }
        })
        .then(version => {
            return wrap(sls.rollback(version));
        });
};
 
module.exports = rollback;