UNPKG

cells-back-compatibility-apps

Version:

Repository where the functional tests of the apps will be executed

96 lines (83 loc) 2.64 kB
'use strict'; const fs = require('fs-extra'); const path = require('path'); const expect = require('chai').expect; const exec = require('child_process').exec; const pctp = require('pisco-callback-to-promise'); /* global define, it, describe, before, beforeEach, afterEach, after */ // constants const testApps = [ { name: 'MyBusiness.es', type: 'novulcanize', config: 'config-dev', platforms: 'webapp' }, { name: 'glomo-bridge.gb', type: 'novulcanize', config: 'global/artichoke', platforms: 'webapp' }, { name: 'enginevents', type: 'vulcanize', config: 'dev', platforms: 'webapp' } ]; const baseApp = `${__dirname}/../node_modules`; const nodeModules = `${__dirname}/../node_modules`; // --- Actions --------- const setPisco = () => { if (!process.env.piscoExec) { process.env.piscoExec = 'cells'; } }; const build = (config) => { return pctp.c2p(exec, `${process.env.piscoExec} app:build --config ${config.config} --type ${config.type}`, {cwd: path.join(baseApp, config.name)}); }; const validate = (config) => { return pctp.c2p(exec, `${process.env.piscoExec} app:validate --config ${config.config} --type ${config.type} --platforms ${config.platforms}`, {cwd: path.join(baseApp, config.name)}); }; const clean = (config) => { return pctp.c2p(fs.ensureDir, path.join(nodeModules, config.name)) .then(() => pctp.c2p(exec, `${process.env.piscoExec} app:clean`, {cwd: path.join(nodeModules, config.name)})); }; const serve = (config) => { return clean(config).then(pctp.c2p(exec, `${process.env.piscoExec} app: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 app:${flow.name} for apps`, () => { beforeEach('Set pisco if necessary', setPisco); testApps.forEach((appConfig) => { it(`Should ${flow.name} app "${appConfig.name}" --> "(${appConfig.type}; ${appConfig.config})"`, (done) => { flow.exec(appConfig) .then((stdout) => { expect(stdout).contain(`Flow [ ${flow.name} ] finished`); }).catch((error) => { pctp.logError(error); return Promise.resolve(error.error ? error.error : error); }).then(done); }).timeout(flow.timeout); }); }); });