|
2 | 2 |
|
3 | 3 | /// <reference path='../../../third_party/typings/node/node.d.ts' /> |
4 | 4 |
|
| 5 | +import fs = require('fs'); |
5 | 6 | import path = require('path'); |
6 | 7 |
|
7 | 8 | export interface RuleConfig { |
@@ -95,6 +96,21 @@ export class Rule { |
95 | 96 | } |
96 | 97 | } |
97 | 98 |
|
| 99 | + public jasmineSingleSpec(file :string) :JasmineRule { |
| 100 | + return { |
| 101 | + src: [ |
| 102 | + require.resolve('arraybuffer-slice'), |
| 103 | + require.resolve('es6-promise'), |
| 104 | + path.join(this.config.thirdPartyBuildPath, 'promise-polyfill.js'), |
| 105 | + ], |
| 106 | + options: { |
| 107 | + specs: [ path.join(this.config.devBuildPath, file + '.spec.static.js') ], |
| 108 | + outfile: path.join(this.config.devBuildPath, file, '/SpecRunner.html'), |
| 109 | + keepRunner: true |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
98 | 114 | // Grunt browserify target creator |
99 | 115 | public browserify(filepath:string, options = { |
100 | 116 | browserifyOptions: { standalone: 'browserified_exports' } |
@@ -215,4 +231,65 @@ export class Rule { |
215 | 231 | return { files: allFilesForlibPaths.concat(copyInfo.files) }; |
216 | 232 | } |
217 | 233 |
|
| 234 | + public buildAndRunTest(test :string, gruntConfig :{[c :string] :{[t :string] :Object}}, |
| 235 | + coverage?:boolean) :string[] { |
| 236 | + var name = test + 'Spec'; |
| 237 | + var browserifyRule = this.browserifySpec(test); |
| 238 | + var jasmineRule = this.jasmineSingleSpec(test); |
| 239 | + |
| 240 | + if (coverage) { |
| 241 | + name += 'Cov'; |
| 242 | + browserifyRule = this.addCoverageToBrowserify(browserifyRule); |
| 243 | + jasmineRule = this.addCoverageToSpec(jasmineRule); |
| 244 | + } |
| 245 | + |
| 246 | + gruntConfig['browserify'][name] = browserifyRule; |
| 247 | + gruntConfig['jasmine'][name] = jasmineRule; |
| 248 | + |
| 249 | + return [ |
| 250 | + 'browserify:' + name, |
| 251 | + 'jasmine:' + name, |
| 252 | + ]; |
| 253 | + } |
| 254 | + |
| 255 | + /* |
| 256 | + * Returns a list of tests that exist within the directory structure of a |
| 257 | + * project. |
| 258 | + * |
| 259 | + * rootDir is the directory under which the layout will match what this file |
| 260 | + * expects for paths being passed in (i.e. under devBuildPath) |
| 261 | + * |
| 262 | + * getTests('src'); |
| 263 | + * Lists all tests under the src/ directory |
| 264 | + * getTests('src', 'generic_ui/scripts'); |
| 265 | + * Lists all tests under the generic_ui/scripts directory, all paths |
| 266 | + * relative to src/ |
| 267 | + * getTests('src', undefined, ['integration-tests']); |
| 268 | + * Lists all the tests under src/ ignoring anything named integration-tests |
| 269 | + */ |
| 270 | + public getTests(rootDir :string, current :string = '', ignore :string[] = []) { |
| 271 | + var tests :string[] = []; |
| 272 | + |
| 273 | + var files = fs.readdirSync(path.join(rootDir, current)); |
| 274 | + for (var f in files) { |
| 275 | + if (ignore.indexOf(files[f]) !== -1) { |
| 276 | + continue; |
| 277 | + } |
| 278 | + |
| 279 | + var file = path.join(current, files[f]); |
| 280 | + |
| 281 | + var stats = fs.statSync(path.join(rootDir, file)); |
| 282 | + if (stats.isDirectory()) { |
| 283 | + tests = tests.concat(this.getTests(rootDir, file, ignore)); |
| 284 | + } else { |
| 285 | + var match = /(.+)\.spec\.ts/.exec(file); |
| 286 | + if (match) { |
| 287 | + tests.push(match[1]); |
| 288 | + } |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + return tests; |
| 293 | + } |
| 294 | + |
218 | 295 | } // class Rule |
0 commit comments