Test that all files have a single provide named like the path
This commit is contained in:
4
Makefile
4
Makefile
@@ -135,6 +135,10 @@ serve: build/test_requires.js build/test_rendering_requires.js
|
||||
test: build/timestamps/node-modules-timestamp build/test_requires.js
|
||||
node tasks/test.js
|
||||
|
||||
.PHONY: test-node
|
||||
test-node: build/timestamps/node-modules-timestamp
|
||||
./node_modules/.bin/mocha test/node
|
||||
|
||||
.PHONY: test-coverage
|
||||
test-coverage: build/timestamps/node-modules-timestamp
|
||||
node tasks/test-coverage.js
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"postinstall": "closure-util update",
|
||||
"start": "node tasks/serve.js",
|
||||
"pretest": "eslint tasks test test_rendering src examples",
|
||||
"test-node": "mocha test/node",
|
||||
"test": "node tasks/test.js",
|
||||
"debug-server": "node tasks/serve-lib.js"
|
||||
},
|
||||
|
||||
5
test/node/.eslintrc
Normal file
5
test/node/.eslintrc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true
|
||||
}
|
||||
}
|
||||
64
test/node/one-provide.js
Normal file
64
test/node/one-provide.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
|
||||
const src = path.join(__dirname, '..', '..', 'src');
|
||||
|
||||
const PROVIDE_RE = /^goog.provide\('(.*)'\);/
|
||||
|
||||
describe('each file', () => {
|
||||
|
||||
const provides = {};
|
||||
|
||||
before(done => {
|
||||
glob('**/*.js', {cwd: src}, function(err, files) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
let count = files.length;
|
||||
let called = false;
|
||||
files.forEach(file => {
|
||||
fs.readFile(path.join(src, file), (err, data) => {
|
||||
if (!called && err) {
|
||||
called = true;
|
||||
return done(err);
|
||||
}
|
||||
provides[file] = [];
|
||||
String(data).split('\n').forEach(line => {
|
||||
const match = line.match(PROVIDE_RE);
|
||||
if (match) {
|
||||
provides[file].push(match[1]);
|
||||
}
|
||||
});
|
||||
--count;
|
||||
if (count === 0 && !called) {
|
||||
called = true;
|
||||
return done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('has a single provide', () => {
|
||||
for (let file in provides) {
|
||||
assert.equal(provides[file].length, 1, 'expected a single provide: ' + file);
|
||||
}
|
||||
});
|
||||
|
||||
it('has a path that maps to the provide', () => {
|
||||
for (let file in provides) {
|
||||
const provide = provides[file][0];
|
||||
let ext;
|
||||
if (file.endsWith('index.js')) {
|
||||
ext = path.sep + 'index.js';
|
||||
} else {
|
||||
ext = '.js';
|
||||
}
|
||||
const mapped = provide.split('.').map(part => part.toLowerCase()).join(path.sep) + ext;
|
||||
assert.equal(mapped, file, 'expected provide to be like the path: ' + file);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user