mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-12 10:10:32 -06:00
decaffeinate: Run post-processing cleanups on project.coffee and 3 others
decaffeinate: Run post-processing cleanups on project_spec.coffee decaffeinate: Run post-processing cleanups on open_project.coffee decaffeinate: Run post-processing cleanups on open_project_spec.coffee Fixed error. Fixed snapshot. Removed returns.
This commit is contained in:
@@ -11,7 +11,7 @@ The error we received was:
|
||||
Cannot find module '/foo/bar/.projects/e2e/node_modules/module-does-not-exist'
|
||||
Require stack:
|
||||
- lib/reporter.coffee
|
||||
- lib/project.coffee
|
||||
- lib/project.js
|
||||
- lib/modes/run.js
|
||||
- lib/modes/index.coffee
|
||||
- lib/cypress.coffee
|
||||
|
||||
@@ -1,256 +1,271 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const _ = require("lodash");
|
||||
const la = require("lazy-ass");
|
||||
const debug = require("debug")("cypress:server:openproject");
|
||||
const Promise = require("bluebird");
|
||||
const path = require("path");
|
||||
const chokidar = require("chokidar");
|
||||
const files = require("./controllers/files");
|
||||
const config = require("./config");
|
||||
const Project = require("./project");
|
||||
const browsers = require("./browsers");
|
||||
const specsUtil = require("./util/specs");
|
||||
const preprocessor = require("./plugins/preprocessor");
|
||||
const _ = require('lodash')
|
||||
const la = require('lazy-ass')
|
||||
const debug = require('debug')('cypress:server:openproject')
|
||||
const Promise = require('bluebird')
|
||||
const chokidar = require('chokidar')
|
||||
const Project = require('./project')
|
||||
const browsers = require('./browsers')
|
||||
const specsUtil = require('./util/specs')
|
||||
const preprocessor = require('./plugins/preprocessor')
|
||||
|
||||
const moduleFactory = function() {
|
||||
let openProject = null;
|
||||
let relaunchBrowser = null;
|
||||
let specsWatcher = null;
|
||||
const moduleFactory = () => {
|
||||
let openProject = null
|
||||
let relaunchBrowser = null
|
||||
let specsWatcher = null
|
||||
|
||||
const reset = function() {
|
||||
openProject = null;
|
||||
return relaunchBrowser = null;
|
||||
};
|
||||
const reset = () => {
|
||||
openProject = null
|
||||
relaunchBrowser = null
|
||||
}
|
||||
|
||||
const tryToCall = method =>
|
||||
function(...args) {
|
||||
const tryToCall = (method) => {
|
||||
return (...args) => {
|
||||
if (openProject) {
|
||||
return openProject[method].apply(openProject, args);
|
||||
} else {
|
||||
return Promise.resolve(null);
|
||||
return openProject[method](...args)
|
||||
}
|
||||
|
||||
return Promise.resolve(null)
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
return {
|
||||
reset: tryToCall("reset"),
|
||||
reset: tryToCall('reset'),
|
||||
|
||||
getConfig: tryToCall("getConfig"),
|
||||
getConfig: tryToCall('getConfig'),
|
||||
|
||||
createCiProject: tryToCall("createCiProject"),
|
||||
createCiProject: tryToCall('createCiProject'),
|
||||
|
||||
getRecordKeys: tryToCall("getRecordKeys"),
|
||||
getRecordKeys: tryToCall('getRecordKeys'),
|
||||
|
||||
getRuns: tryToCall("getRuns"),
|
||||
getRuns: tryToCall('getRuns'),
|
||||
|
||||
requestAccess: tryToCall("requestAccess"),
|
||||
requestAccess: tryToCall('requestAccess'),
|
||||
|
||||
emit: tryToCall("emit"),
|
||||
emit: tryToCall('emit'),
|
||||
|
||||
getProject() { return openProject; },
|
||||
getProject () {
|
||||
return openProject
|
||||
},
|
||||
|
||||
launch(browser, spec, options = {}) {
|
||||
debug("resetting project state, preparing to launch browser");
|
||||
launch (browser, spec, options = {}) {
|
||||
debug('resetting project state, preparing to launch browser')
|
||||
|
||||
la(_.isPlainObject(browser), "expected browser object:", browser);
|
||||
la(_.isPlainObject(browser), 'expected browser object:', browser)
|
||||
|
||||
//# reset to reset server and socket state because
|
||||
//# of potential domain changes, request buffers, etc
|
||||
// reset to reset server and socket state because
|
||||
// of potential domain changes, request buffers, etc
|
||||
return this.reset()
|
||||
.then(() => openProject.getSpecUrl(spec.absolute)).then(url =>
|
||||
openProject.getConfig()
|
||||
.then(function(cfg) {
|
||||
let am;
|
||||
options.browsers = cfg.browsers;
|
||||
options.proxyUrl = cfg.proxyUrl;
|
||||
options.userAgent = cfg.userAgent;
|
||||
options.proxyServer = cfg.proxyUrl;
|
||||
options.socketIoRoute = cfg.socketIoRoute;
|
||||
options.chromeWebSecurity = cfg.chromeWebSecurity;
|
||||
.then(() => openProject.getSpecUrl(spec.absolute))
|
||||
.then((url) => {
|
||||
return openProject.getConfig()
|
||||
.then((cfg) => {
|
||||
options.browsers = cfg.browsers
|
||||
options.proxyUrl = cfg.proxyUrl
|
||||
options.userAgent = cfg.userAgent
|
||||
options.proxyServer = cfg.proxyUrl
|
||||
options.socketIoRoute = cfg.socketIoRoute
|
||||
options.chromeWebSecurity = cfg.chromeWebSecurity
|
||||
|
||||
options.url = url;
|
||||
options.url = url
|
||||
|
||||
options.isTextTerminal = cfg.isTextTerminal;
|
||||
options.isTextTerminal = cfg.isTextTerminal
|
||||
|
||||
//# if we don't have the isHeaded property
|
||||
//# then we're in interactive mode and we
|
||||
//# can assume its a headed browser
|
||||
//# TODO: we should clean this up
|
||||
if (!_.has(browser, "isHeaded")) {
|
||||
browser.isHeaded = true;
|
||||
browser.isHeadless = false;
|
||||
// if we don't have the isHeaded property
|
||||
// then we're in interactive mode and we
|
||||
// can assume its a headed browser
|
||||
// TODO: we should clean this up
|
||||
if (!_.has(browser, 'isHeaded')) {
|
||||
browser.isHeaded = true
|
||||
browser.isHeadless = false
|
||||
}
|
||||
|
||||
//# set the current browser object on options
|
||||
//# so we can pass it down
|
||||
options.browser = browser;
|
||||
// set the current browser object on options
|
||||
// so we can pass it down
|
||||
options.browser = browser
|
||||
|
||||
openProject.setCurrentSpecAndBrowser(spec, browser);
|
||||
openProject.setCurrentSpecAndBrowser(spec, browser)
|
||||
|
||||
const automation = openProject.getAutomation();
|
||||
const automation = openProject.getAutomation()
|
||||
|
||||
//# use automation middleware if its
|
||||
//# been defined here
|
||||
if (am = options.automationMiddleware) {
|
||||
automation.use(am);
|
||||
// use automation middleware if its
|
||||
// been defined here
|
||||
let am = options.automationMiddleware
|
||||
|
||||
if (am) {
|
||||
automation.use(am)
|
||||
}
|
||||
|
||||
automation.use({
|
||||
onBeforeRequest(message, data) {
|
||||
if (message === "take:screenshot") {
|
||||
data.specName = spec.name;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
});
|
||||
onBeforeRequest (message, data) {
|
||||
if (message === 'take:screenshot') {
|
||||
data.specName = spec.name
|
||||
|
||||
const { onBrowserClose } = options;
|
||||
options.onBrowserClose = function() {
|
||||
return data
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const { onBrowserClose } = options
|
||||
|
||||
options.onBrowserClose = () => {
|
||||
if (spec && spec.absolute) {
|
||||
preprocessor.removeFile(spec.absolute, cfg);
|
||||
preprocessor.removeFile(spec.absolute, cfg)
|
||||
}
|
||||
|
||||
if (onBrowserClose) {
|
||||
return onBrowserClose();
|
||||
return onBrowserClose()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return (relaunchBrowser = function() {
|
||||
relaunchBrowser = () => {
|
||||
debug(
|
||||
"launching browser: %o, spec: %s",
|
||||
'launching browser: %o, spec: %s',
|
||||
browser,
|
||||
spec.relative
|
||||
);
|
||||
)
|
||||
|
||||
return browsers.open(browser, options, automation);
|
||||
})();
|
||||
return browsers.open(browser, options, automation)
|
||||
}
|
||||
|
||||
return relaunchBrowser()
|
||||
})
|
||||
);
|
||||
})
|
||||
},
|
||||
|
||||
getSpecChanges(options = {}) {
|
||||
let currentSpecs = null;
|
||||
getSpecChanges (options = {}) {
|
||||
let currentSpecs = null
|
||||
|
||||
_.defaults(options, {
|
||||
onChange() {},
|
||||
onError() {}
|
||||
});
|
||||
onChange: () => { },
|
||||
onError: () => { },
|
||||
})
|
||||
|
||||
const sendIfChanged = function(specs = []) {
|
||||
//# dont do anything if the specs haven't changed
|
||||
if (_.isEqual(specs, currentSpecs)) { return; }
|
||||
const sendIfChanged = (specs = []) => {
|
||||
// dont do anything if the specs haven't changed
|
||||
if (_.isEqual(specs, currentSpecs)) {
|
||||
return
|
||||
}
|
||||
|
||||
currentSpecs = specs;
|
||||
return options.onChange(specs);
|
||||
};
|
||||
currentSpecs = specs
|
||||
|
||||
return options.onChange(specs)
|
||||
}
|
||||
|
||||
const checkForSpecUpdates = _.debounce(() => {
|
||||
if (!openProject) {
|
||||
return this.stopSpecsWatcher();
|
||||
return this.stopSpecsWatcher()
|
||||
}
|
||||
|
||||
debug("check for spec updates");
|
||||
debug('check for spec updates')
|
||||
|
||||
return get()
|
||||
.then(sendIfChanged)
|
||||
.catch(options.onError);
|
||||
}
|
||||
, 250, { leading: true });
|
||||
.catch(options.onError)
|
||||
},
|
||||
250, { leading: true })
|
||||
|
||||
const createSpecsWatcher = function(cfg) {
|
||||
if (specsWatcher) { return; }
|
||||
const createSpecsWatcher = (cfg) => {
|
||||
if (specsWatcher) {
|
||||
return
|
||||
}
|
||||
|
||||
debug("watch test files: %s in %s", cfg.testFiles, cfg.integrationFolder);
|
||||
debug('watch test files: %s in %s', cfg.testFiles, cfg.integrationFolder)
|
||||
|
||||
specsWatcher = chokidar.watch(cfg.testFiles, {
|
||||
cwd: cfg.integrationFolder,
|
||||
ignored: cfg.ignoreTestFiles,
|
||||
ignoreInitial: true
|
||||
});
|
||||
specsWatcher.on("add", checkForSpecUpdates);
|
||||
return specsWatcher.on("unlink", checkForSpecUpdates);
|
||||
};
|
||||
ignoreInitial: true,
|
||||
})
|
||||
|
||||
var get = () =>
|
||||
openProject.getConfig()
|
||||
.then(function(cfg) {
|
||||
createSpecsWatcher(cfg);
|
||||
return specsUtil.find(cfg);}).then((specs = []) =>
|
||||
//# TODO: put back 'integration' property
|
||||
//# on the specs
|
||||
({
|
||||
integration: specs
|
||||
}))
|
||||
;
|
||||
specsWatcher.on('add', checkForSpecUpdates)
|
||||
|
||||
//# immediately check the first time around
|
||||
return checkForSpecUpdates();
|
||||
},
|
||||
|
||||
stopSpecsWatcher() {
|
||||
debug("stop spec watcher");
|
||||
return Promise.try(() => specsWatcher != null ? specsWatcher.close() : undefined);
|
||||
},
|
||||
|
||||
closeBrowser() {
|
||||
return browsers.close();
|
||||
},
|
||||
|
||||
closeOpenProjectAndBrowsers() {
|
||||
return Promise.all([
|
||||
this.closeBrowser(),
|
||||
openProject ? openProject.close() : undefined
|
||||
])
|
||||
.then(function() {
|
||||
reset();
|
||||
|
||||
return null;
|
||||
});
|
||||
},
|
||||
|
||||
close() {
|
||||
debug("closing opened project");
|
||||
|
||||
this.stopSpecsWatcher();
|
||||
return this.closeOpenProjectAndBrowsers();
|
||||
},
|
||||
|
||||
create(path, args = {}, options = {}) {
|
||||
debug("open_project create %s", path);
|
||||
debug("and options %o", options);
|
||||
|
||||
//# store the currently open project
|
||||
openProject = new Project(path);
|
||||
|
||||
_.defaults(options, {
|
||||
onReloadBrowser: (url, browser) => {
|
||||
if (relaunchBrowser) {
|
||||
return relaunchBrowser();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!_.isUndefined(args.configFile)) {
|
||||
options.configFile = args.configFile;
|
||||
return specsWatcher.on('unlink', checkForSpecUpdates)
|
||||
}
|
||||
|
||||
options = _.extend({}, args.config, options);
|
||||
const get = () => {
|
||||
return openProject.getConfig()
|
||||
.then((cfg) => {
|
||||
createSpecsWatcher(cfg)
|
||||
|
||||
//# open the project and return
|
||||
//# the config for the project instance
|
||||
debug("opening project %s", path);
|
||||
debug("and options %o", options);
|
||||
return specsUtil.find(cfg)
|
||||
})
|
||||
// TODO: put back 'integration' property
|
||||
// on the specs
|
||||
.then((specs = []) => {
|
||||
return {
|
||||
integration: specs,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// immediately check the first time around
|
||||
return checkForSpecUpdates()
|
||||
},
|
||||
|
||||
stopSpecsWatcher () {
|
||||
debug('stop spec watcher')
|
||||
|
||||
return Promise.try(() => {
|
||||
return specsWatcher ? specsWatcher.close() : undefined
|
||||
})
|
||||
},
|
||||
|
||||
closeBrowser () {
|
||||
return browsers.close()
|
||||
},
|
||||
|
||||
closeOpenProjectAndBrowsers () {
|
||||
return Promise.all([
|
||||
this.closeBrowser(),
|
||||
openProject ? openProject.close() : undefined,
|
||||
])
|
||||
.then(() => {
|
||||
reset()
|
||||
|
||||
return null
|
||||
})
|
||||
},
|
||||
|
||||
close () {
|
||||
debug('closing opened project')
|
||||
|
||||
this.stopSpecsWatcher()
|
||||
|
||||
return this.closeOpenProjectAndBrowsers()
|
||||
},
|
||||
|
||||
create (path, args = {}, options = {}) {
|
||||
debug('open_project create %s', path)
|
||||
debug('and options %o', options)
|
||||
|
||||
// store the currently open project
|
||||
openProject = new Project(path)
|
||||
|
||||
_.defaults(options, {
|
||||
onReloadBrowser: () => {
|
||||
if (relaunchBrowser) {
|
||||
return relaunchBrowser()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
if (!_.isUndefined(args.configFile)) {
|
||||
options.configFile = args.configFile
|
||||
}
|
||||
|
||||
options = _.extend({}, args.config, options)
|
||||
|
||||
// open the project and return
|
||||
// the config for the project instance
|
||||
debug('opening project %s', path)
|
||||
debug('and options %o', options)
|
||||
|
||||
return openProject.open(options)
|
||||
.return(this);
|
||||
}
|
||||
};
|
||||
};
|
||||
.return(this)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = moduleFactory();
|
||||
module.exports.Factory = moduleFactory;
|
||||
module.exports = moduleFactory()
|
||||
|
||||
module.exports.Factory = moduleFactory
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -342,7 +342,7 @@ describe "lib/cypress", ->
|
||||
.then =>
|
||||
expect(api.createProject).not.to.be.called
|
||||
|
||||
Project(@noScaffolding).getProjectId()
|
||||
(new Project(@noScaffolding)).getProjectId()
|
||||
.then ->
|
||||
throw new Error("should have caught error but did not")
|
||||
.catch (err) ->
|
||||
|
||||
@@ -112,7 +112,7 @@ describe "Routes", ->
|
||||
rp(options)
|
||||
|
||||
open = =>
|
||||
project = Project("/path/to/project")
|
||||
project = new Project("/path/to/project")
|
||||
|
||||
Promise.all([
|
||||
## open our https server
|
||||
|
||||
@@ -18,7 +18,7 @@ specsUtil = require("#{root}../lib/util/specs")
|
||||
|
||||
describe "lib/modes/run", ->
|
||||
beforeEach ->
|
||||
@projectInstance = Project("/_test-output/path/to/project")
|
||||
@projectInstance = new Project("/_test-output/path/to/project")
|
||||
|
||||
context ".getProjectId", ->
|
||||
it "resolves if id", ->
|
||||
|
||||
@@ -1,134 +1,145 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
require("../spec_helper");
|
||||
require('../spec_helper')
|
||||
|
||||
const chokidar = require("chokidar");
|
||||
const browsers = require(`${root}lib/browsers`);
|
||||
const Project = require(`${root}lib/project`);
|
||||
const openProject = require(`${root}lib/open_project`);
|
||||
const preprocessor = require(`${root}lib/plugins/preprocessor`);
|
||||
const chokidar = require('chokidar')
|
||||
const browsers = require(`${root}lib/browsers`)
|
||||
const Project = require(`${root}lib/project`)
|
||||
const openProject = require(`${root}lib/open_project`)
|
||||
const preprocessor = require(`${root}lib/plugins/preprocessor`)
|
||||
|
||||
describe("lib/open_project", function() {
|
||||
beforeEach(function() {
|
||||
describe('lib/open_project', () => {
|
||||
beforeEach(function () {
|
||||
this.automation = {
|
||||
reset: sinon.stub(),
|
||||
use: sinon.stub()
|
||||
};
|
||||
use: sinon.stub(),
|
||||
}
|
||||
|
||||
this.config = {
|
||||
integrationFolder: "/user/foo/cypress/integration",
|
||||
testFiles: "**/*.*",
|
||||
ignoreTestFiles: "**/*.nope"
|
||||
};
|
||||
integrationFolder: '/user/foo/cypress/integration',
|
||||
testFiles: '**/*.*',
|
||||
ignoreTestFiles: '**/*.nope',
|
||||
}
|
||||
|
||||
sinon.stub(browsers, "get").resolves();
|
||||
sinon.stub(browsers, "open");
|
||||
sinon.stub(Project.prototype, "open").resolves();
|
||||
sinon.stub(Project.prototype, "reset").resolves();
|
||||
sinon.stub(Project.prototype, "getSpecUrl").resolves();
|
||||
sinon.stub(Project.prototype, "getConfig").resolves(this.config);
|
||||
sinon.stub(Project.prototype, "getAutomation").returns(this.automation);
|
||||
sinon.stub(preprocessor, "removeFile");
|
||||
sinon.stub(browsers, 'get').resolves()
|
||||
sinon.stub(browsers, 'open')
|
||||
sinon.stub(Project.prototype, 'open').resolves()
|
||||
sinon.stub(Project.prototype, 'reset').resolves()
|
||||
sinon.stub(Project.prototype, 'getSpecUrl').resolves()
|
||||
sinon.stub(Project.prototype, 'getConfig').resolves(this.config)
|
||||
sinon.stub(Project.prototype, 'getAutomation').returns(this.automation)
|
||||
sinon.stub(preprocessor, 'removeFile')
|
||||
|
||||
return openProject.create("/project/root");
|
||||
});
|
||||
openProject.create('/project/root')
|
||||
})
|
||||
|
||||
context("#launch", function() {
|
||||
beforeEach(function() {
|
||||
context('#launch', () => {
|
||||
beforeEach(function () {
|
||||
this.spec = {
|
||||
absolute: "path/to/spec"
|
||||
};
|
||||
absolute: 'path/to/spec',
|
||||
}
|
||||
|
||||
return this.browser = { name: "chrome" };});
|
||||
this.browser = { name: 'chrome' }
|
||||
})
|
||||
|
||||
it("tells preprocessor to remove file on browser close", function() {
|
||||
it('tells preprocessor to remove file on browser close', function () {
|
||||
return openProject.launch(this.browser, this.spec)
|
||||
.then(function() {
|
||||
browsers.open.lastCall.args[1].onBrowserClose();
|
||||
return expect(preprocessor.removeFile).to.be.calledWith("path/to/spec");
|
||||
});
|
||||
});
|
||||
.then(() => {
|
||||
browsers.open.lastCall.args[1].onBrowserClose()
|
||||
|
||||
it("does not tell preprocessor to remove file if no spec", function() {
|
||||
expect(preprocessor.removeFile).to.be.calledWith('path/to/spec')
|
||||
})
|
||||
})
|
||||
|
||||
it('does not tell preprocessor to remove file if no spec', function () {
|
||||
return openProject.launch(this.browser, {})
|
||||
.then(function() {
|
||||
browsers.open.lastCall.args[1].onBrowserClose();
|
||||
return expect(preprocessor.removeFile).not.to.be.called;
|
||||
});
|
||||
});
|
||||
.then(() => {
|
||||
browsers.open.lastCall.args[1].onBrowserClose()
|
||||
|
||||
expect(preprocessor.removeFile).not.to.be.called
|
||||
})
|
||||
})
|
||||
|
||||
it('runs original onBrowserClose callback on browser close', function () {
|
||||
const onBrowserClose = sinon.stub()
|
||||
const options = { onBrowserClose }
|
||||
|
||||
it("runs original onBrowserClose callback on browser close", function() {
|
||||
const onBrowserClose = sinon.stub();
|
||||
const options = { onBrowserClose };
|
||||
return openProject.launch(this.browser, this.spec, options)
|
||||
.then(function() {
|
||||
browsers.open.lastCall.args[1].onBrowserClose();
|
||||
return expect(onBrowserClose).to.be.called;
|
||||
});
|
||||
});
|
||||
.then(() => {
|
||||
browsers.open.lastCall.args[1].onBrowserClose()
|
||||
|
||||
it("calls project.reset on launch", function() {
|
||||
expect(onBrowserClose).to.be.called
|
||||
})
|
||||
})
|
||||
|
||||
it('calls project.reset on launch', function () {
|
||||
return openProject.launch(this.browser, this.spec)
|
||||
.then(() => expect(Project.prototype.reset).to.be.called);
|
||||
});
|
||||
.then(() => {
|
||||
expect(Project.prototype.reset).to.be.called
|
||||
})
|
||||
})
|
||||
|
||||
return it("sets isHeaded + isHeadless if not already defined", function() {
|
||||
expect(this.browser.isHeaded).to.be.undefined;
|
||||
expect(this.browser.isHeadless).to.be.undefined;
|
||||
it('sets isHeaded + isHeadless if not already defined', function () {
|
||||
expect(this.browser.isHeaded).to.be.undefined
|
||||
expect(this.browser.isHeadless).to.be.undefined
|
||||
|
||||
return openProject.launch(this.browser, this.spec)
|
||||
.then(() => {
|
||||
expect(this.browser.isHeaded).to.be.true;
|
||||
return expect(this.browser.isHeadless).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(this.browser.isHeaded).to.be.true
|
||||
|
||||
return context("#getSpecChanges", function() {
|
||||
beforeEach(function() {
|
||||
expect(this.browser.isHeadless).to.be.false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
context('#getSpecChanges', () => {
|
||||
beforeEach(function () {
|
||||
this.watcherStub = {
|
||||
on: sinon.stub()
|
||||
};
|
||||
return sinon.stub(chokidar, "watch").returns(this.watcherStub);
|
||||
});
|
||||
on: sinon.stub(),
|
||||
}
|
||||
|
||||
it("watches spec files", function() {
|
||||
sinon.stub(chokidar, 'watch').returns(this.watcherStub)
|
||||
})
|
||||
|
||||
it('watches spec files', function () {
|
||||
return openProject.getSpecChanges({}).then(() => {
|
||||
return expect(chokidar.watch).to.be.calledWith(this.config.testFiles, {
|
||||
expect(chokidar.watch).to.be.calledWith(this.config.testFiles, {
|
||||
cwd: this.config.integrationFolder,
|
||||
ignored: this.config.ignoreTestFiles,
|
||||
ignoreInitial: true
|
||||
});
|
||||
});
|
||||
});
|
||||
ignoreInitial: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("calls onChange callback when file is added", function() {
|
||||
const onChange = sinon.spy();
|
||||
this.watcherStub.on.withArgs("add").yields();
|
||||
return openProject.getSpecChanges({ onChange }).then(() => {
|
||||
return expect(onChange).to.be.called;
|
||||
});
|
||||
});
|
||||
it('calls onChange callback when file is added', function () {
|
||||
const onChange = sinon.spy()
|
||||
|
||||
it("calls onChange callback when file is removed", function() {
|
||||
const onChange = sinon.spy();
|
||||
this.watcherStub.on.withArgs("unlink").yields();
|
||||
return openProject.getSpecChanges({ onChange }).then(() => {
|
||||
return expect(onChange).to.be.called;
|
||||
});
|
||||
});
|
||||
this.watcherStub.on.withArgs('add').yields()
|
||||
|
||||
return it("only calls onChange once if there are multiple changes in a row", function() {
|
||||
const onChange = sinon.spy();
|
||||
this.watcherStub.on.withArgs("unlink").yields();
|
||||
this.watcherStub.on.withArgs("add").yields();
|
||||
this.watcherStub.on.withArgs("unlink").yields();
|
||||
this.watcherStub.on.withArgs("add").yields();
|
||||
return openProject.getSpecChanges({ onChange }).then(() => {
|
||||
return expect(onChange).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(onChange).to.be.called
|
||||
})
|
||||
})
|
||||
|
||||
it('calls onChange callback when file is removed', function () {
|
||||
const onChange = sinon.spy()
|
||||
|
||||
this.watcherStub.on.withArgs('unlink').yields()
|
||||
|
||||
return openProject.getSpecChanges({ onChange }).then(() => {
|
||||
expect(onChange).to.be.called
|
||||
})
|
||||
})
|
||||
|
||||
it('only calls onChange once if there are multiple changes in a row', function () {
|
||||
const onChange = sinon.spy()
|
||||
|
||||
this.watcherStub.on.withArgs('unlink').yields()
|
||||
this.watcherStub.on.withArgs('add').yields()
|
||||
this.watcherStub.on.withArgs('unlink').yields()
|
||||
this.watcherStub.on.withArgs('add').yields()
|
||||
|
||||
return openProject.getSpecChanges({ onChange }).then(() => {
|
||||
expect(onChange).to.be.calledOnce
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@ describe "lib/scaffold", ->
|
||||
|
||||
it "is false when files.length isnt 1", ->
|
||||
id = =>
|
||||
@ids = Project(@idsPath)
|
||||
@ids = new Project(@idsPath)
|
||||
@ids.getConfig()
|
||||
.then (cfg) =>
|
||||
@ids.scaffold(cfg).return(cfg)
|
||||
@@ -42,7 +42,7 @@ describe "lib/scaffold", ->
|
||||
expect(ret).to.be.false
|
||||
|
||||
todo = =>
|
||||
@todos = Project(@todosPath)
|
||||
@todos = new Project(@todosPath)
|
||||
@todos.getConfig()
|
||||
.then (cfg) =>
|
||||
@todos.scaffold(cfg).return(cfg)
|
||||
@@ -55,7 +55,7 @@ describe "lib/scaffold", ->
|
||||
|
||||
it "is true when files, name + bytes match to scaffold", ->
|
||||
## TODO this test really can move to scaffold
|
||||
pristine = Project(@pristinePath)
|
||||
pristine = new Project(@pristinePath)
|
||||
pristine.getConfig()
|
||||
.then (cfg) ->
|
||||
pristine.scaffold(cfg).return(cfg)
|
||||
@@ -66,7 +66,7 @@ describe "lib/scaffold", ->
|
||||
|
||||
it "is false when bytes dont match scaffold", ->
|
||||
## TODO this test really can move to scaffold
|
||||
pristine = Project(@pristinePath)
|
||||
pristine = new Project(@pristinePath)
|
||||
pristine.getConfig()
|
||||
.then (cfg) ->
|
||||
pristine.scaffold(cfg).return(cfg)
|
||||
|
||||
Reference in New Issue
Block a user