Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JSDocs checks #1081

Merged
merged 13 commits into from
Nov 30, 2017
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ install:

script:
- gulp test
- gulp docs:build

after_success:
- npm run coveralls
Expand Down
26 changes: 18 additions & 8 deletions gulp-tasks/test-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,33 @@ const runNodeTestSuite = async (testPath, nodeEnv) => {
}
};

const runNodeTestsWithEnv = async (nodeEnv) => {
let globFolderPattern = global.packageOrStar;
// This means will run the package tests along with the "all" tests.
if (global.packageOrStar !== '*') {
globFolderPattern = `{${[global.packageOrStar, 'all'].join(',')}}`;
const runNodeTestsWithEnv = async (testGroup, nodeEnv) => {
let globConfig = {
ignore: [
'**/all/**',
],
};

if (testGroup === 'all') {
globConfig.ignore = [];
}
const packagesToTest = glob.sync(`test/${globFolderPattern}/node`);

const packagesToTest = glob.sync(`test/${testGroup}/node`, globConfig);
for (const packageToTest of packagesToTest) {
await runNodeTestSuite(packageToTest, nodeEnv);
}
};

gulp.task('test-node:prod', gulp.series(
() => runNodeTestsWithEnv(constants.BUILD_TYPES.prod),
() => runNodeTestsWithEnv(global.packageOrStar, constants.BUILD_TYPES.prod),
));

gulp.task('test-node:dev', gulp.series(
() => runNodeTestsWithEnv(constants.BUILD_TYPES.dev),
() => runNodeTestsWithEnv(global.packageOrStar, constants.BUILD_TYPES.dev),
));

gulp.task('test-node:all', gulp.series(
() => runNodeTestsWithEnv('all', constants.BUILD_TYPES.prod),
));

gulp.task('test-node:clean', () => {
Expand All @@ -76,5 +85,6 @@ gulp.task('test-node', gulp.series(
'test-node:clean',
'test-node:dev',
'test-node:prod',
'test-node:all',
'test-node:coverage',
));
2 changes: 1 addition & 1 deletion jsdoc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"packages/workbox-cli"
],
"includePattern": ".+\\.(js(doc|x)?|mjs)$",
"excludePattern": "((^|\\/|\\\\)build(\\/|\\\\)|(^|\\/|\\\\)test(\\/|\\\\)|(^|\\/|\\\\)node_modules(\\/|\\\\)|(^|\\/|\\\\)demo(\\/|\\\\))"
"excludePattern": "((^|\\/|\\\\)packages\\/.*\\/build(\\/|\\\\)|(^|\\/|\\\\)test(\\/|\\\\)|(^|\\/|\\\\)node_modules(\\/|\\\\)|(^|\\/|\\\\)demo(\\/|\\\\))"
},
"opts": {
"recurse": true
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions test/all/node/test-jsdocs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import path from 'path';
import glob from 'glob';
import {expect} from 'chai';
import fs from 'fs-extra';
import spawn from '../../../gulp-tasks/utils/spawn-promise-wrapper';

describe('[all] JSDocs', function() {
it('should run JSDocs and have no unexpected results', async function() {
// Windows is super unhappy with the JSDocs build pipeline.
// With gulp.cmd in spawn, the query string used by the baseline template
// causes issues.
if (process.platform === 'win32') {
this.skip();
return;
}
// Building docs takes time.
this.timeout(60 * 1000);

const projectRoot = path.join(__dirname, '..', '..', '..');
const docsPath = path.join(projectRoot, 'docs');
await spawn('gulp', ['docs:build'], {
cwd: projectRoot,
});

const docs = glob.sync('*.html', {
cwd: docsPath,
});

// global.html is only added when the docs have stray global values.
if (docs.indexOf('global.html') !== -1) {
throw new Error('There should be **no** globals in the JSDocs.');
}

// On some occassions module.exports can leak into JSDocs and breaks
// in the final template.
expect(docs.indexOf('index-all.html')).to.not.equal(-1);
const indexAllContents = fs.readFileSync(path.join(docsPath, 'index-all.html'))
.toString();
if (indexAllContents.indexOf('<a href="module.html#.exports">module.exports</a>') !== -1) {
throw new Error('There is a stray `module.exports` in the docs. ' +
'Find and fix this issue.');
}
});
});