Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Oct 21, 2020
1 parent 16d3b9c commit 4eed4b3
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 368 deletions.
30 changes: 12 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const path = require('path');
require('isomorphic-fetch');

const allowCorsMiddleware = function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
return next();
};
const fetch = require('isomorphic-fetch');
const webpackConfig = require('./webpack.config.js');

module.exports = function () {
// Project configuration
const pkg = this.file.readJSON('package.json');

this.initConfig({
pkg: this.file.readJSON('package.json'),
pkg,

// Schemas
yaml: {
Expand All @@ -28,7 +24,7 @@ module.exports = function () {

// Building for browser
webpack: {
build: require('./webpack.config.js'),
build: webpackConfig,
},

watch: {
Expand Down Expand Up @@ -104,6 +100,7 @@ module.exports = function () {
this.loadNpmTasks('grunt-exec');

this.registerTask('examples:bundle', () => {
// eslint-disable-next-line global-require
const examples = require('./examples');
return examples.bundle();
});
Expand All @@ -128,34 +125,31 @@ module.exports = function () {
(err) => callback(err));
});

this.registerTask('build', 'Build', (target) => {
if (target == null) { target = 'all'; }
this.registerTask('build', 'Build', (target = 'all') => {
this.task.run('yaml');
if (['all', 'browser'].includes(target)) {
this.task.run('webpack');
this.task.run('examples:bundle');
return this.task.run('copy:ui');
this.task.run('copy:ui');
}
});

this.registerTask('test', 'Build and run tests', (target) => {
if (target == null) { target = 'all'; }
this.registerTask('test', 'Build and run tests', (target = 'all') => {
this.task.run('yamllint');
this.task.run(`build:${target}`);
if (['all', 'nodejs'].includes(target)) {
this.task.run('mochaTest');
}
if (['all', 'browser'].includes(target)) {
this.task.run('downloadfile');
return this.task.run('karma');
this.task.run('karma');
}
});

this.registerTask('default', ['test']);

return this.registerTask('dev', 'Developing', (target) => {
if (target == null) { target = 'all'; }
this.task.run('test');
return this.task.run('watch');
this.registerTask('dev', 'Developing', (target = 'all') => {
this.task.run(`test:${target}`);
this.task.run('watch');
});
};
2 changes: 1 addition & 1 deletion lib/expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function extractMatches(expectation, data) {
exports.expect = function expect(expects, portsdata) {
// can have one or more set of expectations of messages
if (!common.isArray(expects)) {
expect([expects]);
expect([expects], portsdata);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// # Run fbp-spec testcases using Mocha as a runner/frontend
// # Intended to allow reuse of Mocha reporters, or
// # to quickly add a couple of fbp-spec cases to a predominantly Mocha-based testsuite
// # See also ./mochacompat.coffee
// # See also ./mochacompat.js

const debug = require('debug')('fbp-spec:mocha');

Expand Down
2 changes: 1 addition & 1 deletion lib/mochacompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ runTest(mocha/LoadTestCase) OUT -> IN verifyResult(mocha/CheckResults)\

function dumpSpecs(suites) {
// eslint-disable-next-line global-require
const yaml = window.jsyaml ? window.jsyaml : require('js-yaml');
const yaml = (typeof window !== 'undefined' && window.jsyaml) ? window.jsyaml : require('js-yaml');

let str = '';
const delimiter = '---\n';
Expand Down
81 changes: 40 additions & 41 deletions lib/protocol.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// FBP protocol dependent code

let getComponents;
const fbpGraph = require('fbp-graph');
const common = require('./common');
const debug = require('debug')('fbp-spec:protocol');
const Promise = require('bluebird');
const common = require('./common');

exports.sendGraph = function (client, graph, callback) {
exports.sendGraph = function sendGraph(client, graph, callback) {
const main = false; // this is a component?
if (!graph) { return callback(new Error('Graph not defined')); }
if (!graph) {
callback(new Error('Graph not defined'));
return;
}

let graphId = graph.name || graph.properties.id;
if (!graphId) { graphId = `fixture.${common.randomString(10)}`; }
graph.name = graphId;
const g = graph;
g.name = graphId;

if (!(graph instanceof fbpGraph.Graph)) {
// fbp-client operates on fbp-graph instances
fbpGraph.graph.loadJSON(graph, (err, g) => {
if (err) { return callback(err); }
return exports.sendGraph(client, g, callback);
fbpGraph.graph.loadJSON(graph, (err, loadedGraph) => {
if (err) {
callback(err);
return;
}
exports.sendGraph(client, loadedGraph, callback);
});
return;
}
Expand All @@ -39,7 +37,7 @@ exports.sendGraph = function (client, graph, callback) {
.nodeify(callback);
};

exports.startNetwork = function (client, graphId, callback) {
exports.startNetwork = function startNetwork(client, graphId, callback) {
debug('startnetwork', graphId);

Promise.resolve()
Expand All @@ -49,7 +47,7 @@ exports.startNetwork = function (client, graphId, callback) {
.nodeify(callback);
};

exports.stopNetwork = function (client, graphId, callback) {
exports.stopNetwork = function stopNetwork(client, graphId, callback) {
debug('stopnetwork', graphId);

Promise.resolve()
Expand All @@ -59,7 +57,7 @@ exports.stopNetwork = function (client, graphId, callback) {
.nodeify(callback);
};

exports.sendPackets = function (client, graphId, packets, callback) {
exports.sendPackets = function sendPackets(client, graphId, packets, callback) {
debug('sendpackets', graphId, packets);

Promise.all(Object.keys(packets).map((port) => client.protocol.runtime.packet({
Expand All @@ -71,55 +69,56 @@ exports.sendPackets = function (client, graphId, packets, callback) {
.nodeify(callback);
};

exports.getComponents = (getComponents = function (client, callback) {
exports.getComponents = function getComponents(client, callback) {
debug('get components');

Promise.resolve()
.then(() => client.protocol.component.list())
.then((componentList) => {
const components = {};
for (const component of Array.from(componentList)) {
componentList.forEach((component) => {
components[component.name] = component;
}
});
return components;
})
.nodeify(callback);
});
};

exports.getCapabilities = function (client, callback) {
exports.getCapabilities = function getCapabilities(client, callback) {
const def = client.definition;
if (__guard__(def != null ? def.capabilities : undefined, (x) => x.length)) { return callback(null, def.capabilities); }
if (def && def.capabilities && def.capabilities.length) {
// We already know the capabilities
callback(null, def.capabilities);
return;
}
Promise.resolve()
.then(() => client.protocol.runtime.getruntime())
.then((definition) => definition.capabilities)
.nodeify(callback);
};

exports.getComponentTests = function (client, callback) {
exports.getComponentTests = function getComponentTests(client, callback) {
debug('get component tests');

Promise.resolve()
.then(() => client.protocol.component.list())
.then((components) => Promise.all(components.map((component) => client.protocol.component.getsource({
name: component.name,
}).then(
(source) => source,
(err) => ({
tests: null,
}),
))))
.then((components) => Promise.all(components.map((component) => client
.protocol.component.getsource({
name: component.name,
}).then(
(source) => source,
() => ({
tests: null,
}),
))))
.then((sources) => {
const tests = {};
for (const source of Array.from(sources)) {
if (!source.tests) { continue; }
sources.forEach((source) => {
if (!source.tests) { return; }
const name = source.library ? `${source.library}/${source.name}` : source.name;
tests[name] = source.tests;
}
});
return tests;
})
.nodeify(callback);
};

function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
}
Loading

0 comments on commit 4eed4b3

Please sign in to comment.