UNPKG

cells-component-back-compatibility

Version:

Repository where the functional tests of the components will be executed

96 lines (82 loc) 2.45 kB
'use strict'; const fs = require('fs-extra'); const path = require('path'); const expect = require('chai').expect; const exec = require('child_process').exec; const p = require('pisco-callback-to-promise'); const rimraf = require('rimraf'); /* global define, it, describe, before, beforeEach, afterEach, after */ // constants const base = `${__dirname}/../tmp`; const context = 'component'; const componentsCreated = [ { name: 'some-theme', type: 'theme' }, { name: 'some-behavior', type: 'behavior' }, { name: 'some-component', type: 'component' }, { name: 'some-data-manager', type: 'data-manager' } ]; // --- Actions --------- const setPisco = () => { if (!process.env.piscoExec) { process.env.piscoExec = 'cells'; } }; const clone = (config) => { return p.c2p(fs.ensureDir, base) .then(() => p.c2p(exec, `git clone ${config.url}`, {cwd: base})); }; const create = (config) => { return p.c2p(exec, `${process.env.piscoExec} component:create --componentType ${config.type} --b-skipYeomanParams.value true`, {cwd: base}); }; const validate = (config) => { return create(config) .then(() => p.c2p(exec, `${process.env.piscoExec} ${context}:validate`, {cwd: path.join(base, config.name)})); }; const flowsToTest = () => { return [ { name: 'validate', exec: validate, timeout: 500000 } ]; }; // ---- Tests -------- flowsToTest().forEach((flow) => { describe('Run cells component:create and component:validate', () => { beforeEach('Set pisco if necessary', setPisco); before('Copy the yeoman configuration and create the working folder', () => { return p.c2p(rimraf, base, {}) .then(() => p.c2p(fs.mkdir, base)) .then(() => fs.copy(path.join(__dirname, '.yo-rc.json'), path.join(base, '.yo-rc.json'))); }); componentsCreated.forEach((config) => { it(`Should build ${context} "${config.name}" --> "(${config.type})"`, (done) => { flow.exec(config) .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()); }); }); });