Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: lib/src/prism/tests/helper/test-discovery.js

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 "use strict";
2
3 var fs = require("fs");
4 var path = require("path");
5
6
7 module.exports = {
8
9 /**
10 * Loads the list of all available tests
11 *
12 * @param {string} rootDir
13 * @returns {Object.<string, string[]>}
14 */
15 loadAllTests: function (rootDir) {
16 var testSuite = {};
17 var self = this;
18
19 this.getAllDirectories(rootDir).forEach(
20 function (language) {
21 testSuite[language] = self.getAllFiles(path.join (rootDir, language));
22 }
23 );
24
25 return testSuite;
26 },
27
28 /**
29 * Loads the list of available tests that match the given languages
30 *
31 * @param {string} rootDir
32 * @param {string|string[]} languages
33 * @returns {Object.<string, string[]>}
34 */
35 loadSomeTests: function (rootDir, languages) {
36 var testSuite = {};
37 var self = this;
38
39 this.getSomeDirectories(rootDir, languages).forEach(
40 function (language) {
41 testSuite[language] = self.getAllFiles(path.join (rootDir, language));
42 }
43 );
44
45 return testSuite;
46 },
47
48
49 /**
50 * Returns a list of all (sub)directories (just the directory names, not full paths)
51 * in the given src directory
52 *
53 * @param {string} src
54 * @returns {Array.<string>}
55 */
56 getAllDirectories: function (src) {
57 return fs.readdirSync(src).filter(
58 function (file) {
59 return fs.statSync(path.join(src, file)).isDirec tory();
60 }
61 );
62 },
63
64 /**
65 * Returns a list of all (sub)directories (just the directory names, not full paths)
66 * in the given src directory, matching the given languages
67 *
68 * @param {string} src
69 * @param {string|string[]} languages
70 * @returns {Array.<string>}
71 */
72 getSomeDirectories: function (src, languages) {
73 var self = this;
74 return fs.readdirSync(src).filter(
75 function (file) {
76 return fs.statSync(path.join(src, file)).isDirec tory() && self.directoryMatches(file, languages);
77 }
78 );
79 },
80
81 /**
82 * Returns whether a directory matches one of the given languages.
83 * @param {string} directory
84 * @param {string|string[]} languages
85 */
86 directoryMatches: function (directory, languages) {
87 if (!Array.isArray(languages)) {
88 languages = [languages];
89 }
90 var dirLanguages = directory.split(/!?\+!?/);
91 return dirLanguages.some(function (lang) {
92 return languages.indexOf(lang) >= 0;
93 });
94 },
95
96
97 /**
98 * Returns a list of all full file paths to all files in the given src d irectory
99 *
100 * @private
101 * @param {string} src
102 * @returns {Array.<string>}
103 */
104 getAllFiles: function (src) {
105 return fs.readdirSync(src).filter(
106 function (fileName) {
107 // only find files that have the ".test" extensi on
108 return ".test" === path.extname(fileName) &&
109 fs.statSync(path.join(src, fileName)).is File();
110 }
111 ).map(
112 function (fileName) {
113 return path.join(src, fileName);
114 }
115 );
116 }
117 };
OLDNEW
« no previous file with comments | « lib/src/prism/tests/helper/test-case.js ('k') | lib/src/prism/tests/helper/token-stream-transformer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698