Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 90100bf

Browse files
authored
chore: ability to add unit test boilerplate (#2462)
1 parent 6c7f330 commit 90100bf

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

gulpfile.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var DOCS_PATH = path.join(PUBLIC_PATH, 'docs');
3838

3939
var EXAMPLES_PATH = path.join(DOCS_PATH, '_examples');
4040
var EXAMPLES_PROTRACTOR_PATH = path.join(EXAMPLES_PATH, '_protractor');
41+
var EXAMPLES_TESTING_PATH = path.join(EXAMPLES_PATH, 'testing/ts');
4142
var NOT_API_DOCS_GLOB = path.join(PUBLIC_PATH, './{docs/*/latest/!(api),!(docs)}/**/*.*');
4243
var RESOURCES_PATH = path.join(PUBLIC_PATH, 'resources');
4344
var LIVE_EXAMPLES_PATH = path.join(RESOURCES_PATH, 'live-examples');
@@ -97,14 +98,19 @@ var _exampleBoilerplateFiles = [
9798
'tsconfig.json',
9899
'tslint.json',
99100
'typings.json'
100-
];
101+
];
101102

102103
var _exampleDartWebBoilerPlateFiles = ['a2docs.css', 'styles.css'];
103104

104105
var _exampleProtractorBoilerplateFiles = [
105106
'tsconfig.json'
106107
];
107108

109+
var _exampleUnitTestingBoilerplateFiles = [
110+
'karma-test-shim.js',
111+
'karma.conf.js'
112+
];
113+
108114
var _exampleConfigFilename = 'example-config.json';
109115

110116
var _styleLessName = 'a2docs.less';
@@ -497,9 +503,17 @@ function copyExampleBoilerplate() {
497503
.then(function() {
498504
var protractorSourceFiles =
499505
_exampleProtractorBoilerplateFiles
500-
.map(function(name) {return path.join(EXAMPLES_PROTRACTOR_PATH, name);});;
506+
.map(function(name) {return path.join(EXAMPLES_PROTRACTOR_PATH, name); });
501507
var e2eSpecPaths = getE2eSpecPaths(EXAMPLES_PATH);
502508
return copyFiles(protractorSourceFiles, e2eSpecPaths, destFileMode);
509+
})
510+
// copy the unit test boilerplate
511+
.then(function() {
512+
var unittestSourceFiles =
513+
_exampleUnitTestingBoilerplateFiles
514+
.map(function(name) { return path.join(EXAMPLES_TESTING_PATH, name); });
515+
var unittestPaths = getUnitTestingPaths(EXAMPLES_PATH);
516+
return copyFiles(unittestSourceFiles, unittestPaths, destFileMode);
503517
});
504518
}
505519

@@ -894,7 +908,7 @@ function harpCompile() {
894908
} else {
895909
gutil.log(`Harp full site compile, including API docs for all languages.`);
896910
if (skipLangs)
897-
gutil.log(`Ignoring API docs skip set (${skipLangs}) because full ` +
911+
gutil.log(`Ignoring API docs skip set (${skipLangs}) because full ` +
898912
`site has not been built yet or some API HTML files are missing.`);
899913
}
900914

@@ -1130,6 +1144,14 @@ function getDartExampleWebPaths(basePath) {
11301144
return paths;
11311145
}
11321146

1147+
function getUnitTestingPaths(basePath) {
1148+
var examples = getPaths(basePath, _exampleConfigFilename, true);
1149+
return examples.filter((example) => {
1150+
var exampleConfig = fs.readJsonSync(`${example}/${_exampleConfigFilename}`, {throws: false});
1151+
return exampleConfig && !!exampleConfig.unittesting;
1152+
});
1153+
}
1154+
11331155
function getPaths(basePath, filename, includeBase) {
11341156
var filenames = getFilenames(basePath, filename, includeBase);
11351157
var paths = filenames.map(function(fileName) {
@@ -1164,7 +1186,7 @@ function watchAndSync(options, cb) {
11641186

11651187
// When using the --focus=name flag, only **/name/**/*.* example files and
11661188
// **/name.jade files are watched. This is useful for performance reasons.
1167-
// Example: gulp serve-and-sync --focus=architecture
1189+
// Example: gulp serve-and-sync --focus=architecture
11681190
var focus = argv.focus;
11691191

11701192
if (options.devGuide) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"unittesting": true
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"unittesting": true
3+
}

0 commit comments

Comments
 (0)