embed-support
Version:
Create embed codes for a static web project
61 lines (48 loc) • 1.77 kB
JavaScript
/* eslint-disable no-undef */
/* eslint-disable no-unused-expressions */
/* eslint-disable no-console */
// The tests assume that they are run from
// the project root folder
const chai = require('chai');
const expect = chai.expect;
const chaiFiles = require('chai-files');
const spawn = require('child_process').spawn;
const path = require('path');
const file = chaiFiles.file;
const del = require('del');
chai.use(chaiFiles);
function check() {
expect(file('./temp/embed-codes.html')).to.not.be.empty;
expect(file('./temp/embed.js')).to.not.be.empty;
expect(file('./temp/resize.js')).to.not.be.empty;
expect(file('./temp/embed-codes.html')).to.contain('http://www.foo.com/embed/?param=hello');
expect(file('./temp/embed-codes.html')).to.contain('http://www.foo.com/embed/embed.js');
expect(file('./temp/embed-codes.html')).to.contain('http://www.foo.com/embed/resize.js');
}
describe('works via command line', () => {
function followProcessAndCheck(p, done) {
p.on('close', (code) => {
if (code > 0) return done(new Error(`Command exited with code ${code}`));
check();
return done();
});
}
it('works with options object file', done => {
del(['temp']);
const p = spawn(path.resolve('./lib/main-cli.js'),
['--verbose'], { cwd: __dirname, stdio: 'inherit' });
followProcessAndCheck(p, done);
});
it('works with options given on command line', done => {
del(['temp']);
const p = spawn(path.resolve('./lib/main-cli.js'),
[
'--verbose',
'--dest=../temp',
'--destUrl=http://www.foo.com/embed/',
'--iframeUrl=http://www.foo.com/embed/?param=hello',
],
{ cwd: __dirname, stdio: 'inherit' });
followProcessAndCheck(p, done);
});
});