UNPKG

cells-back-compatibility-apps

Version:

Repository where the functional tests of the apps will be executed

117 lines (103 loc) 3.14 kB
'use strict'; /* global define, it, describe, before, beforeEach, after */ const path = require('path'); const exec = require('child_process').exec; const rimraf = require('rimraf'); const util = require('util'); const fs = require('fs-extra'); const expect = require('chai').expect; const p = require('pisco-callback-to-promise'); // constants const testApps = [ { paramsFile: 'composer_one_family.json', name: 'app-one-family', type: 'novulcanize', config: 'local', platforms: 'webapp' }, { paramsFile: 'composer_no_families.json', name: 'app-no-families', type: 'novulcanize', config: 'local', platforms: 'webapp' } ]; const setPisco = () => { if (!process.env.piscoExec) { process.env.piscoExec = 'cells'; } }; const base = `${__dirname}/../tmp`; const context = 'app'; // Actions const create = (config) => { return p.c2p(exec, `${process.env.piscoExec} ${context}:create --paramsFile ${base}/../test/${config.paramsFile}`, {cwd: base}); }; const build = (config) => { return create(config) .then(() => p.c2p(exec, `${process.env.piscoExec} ${context}:build --config ${config.config} --type ${config.type}`, {cwd: path.join(base, config.name)})); }; const validate = (config) => { return create(config) .then(() => p.c2p(exec, `${process.env.piscoExec} ${context}:validate --config ${config.config} --type ${config.type} --platforms ${config.platforms}`, {cwd: path.join(base, config.name)})); }; const clean = (config) => { return create(config) .then(() => p.c2p(exec, `${process.env.piscoExec} ${context}:clean`, {cwd: path.join(base, config.name)})); }; const serve = (config) => { return clean(config).then(p.c2p(exec, `${process.env.piscoExec} ${context}:serve --config ${config.config} --type ${config.type}`, {cwd: path.join(nodeModules, config.name)})); }; const flowsToTest = () => { return [ { name: 'clean', exec: clean, timeout: 500000 }, { name: 'build', exec: build, timeout: 500000 }, { name: 'validate', exec: validate, timeout: 500000 } ]; }; // ---- Tests -------- flowsToTest().forEach((flow) => { describe(`Run cells (with create) app:${flow.name} for apps`, () => { beforeEach('Set pisco if necessary', setPisco); before('Create the working folder', () => { return p.c2p(rimraf, base, {}) .then(() => p.c2p(fs.mkdir, base)); }); testApps.forEach((appConfig) => { it(`Should ${flow.name} app with create "${appConfig.name}" --> "(${appConfig.type}; ${appConfig.config})"`, (done) => { flow.exec(appConfig) .then((stdout) => { expect(stdout).contain(`Flow [ ${flow.name} ] finished`); }) .catch((error) => { p.logError(error); return Promise.resolve(error.error ? error.error : error); }).then(done); }).timeout(flow.timeout); after('Should delete the tmp directory', (done) => { p.c2p(fs.remove, base) .then(() => done()); }); }); }); });