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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/prism/tests/helper/test-discovery.js
diff --git a/lib/src/prism/tests/helper/test-discovery.js b/lib/src/prism/tests/helper/test-discovery.js
new file mode 100644
index 0000000000000000000000000000000000000000..622b6192711569d33bbbfeb69400ddd070132ee8
--- /dev/null
+++ b/lib/src/prism/tests/helper/test-discovery.js
@@ -0,0 +1,117 @@
+"use strict";
+
+var fs = require("fs");
+var path = require("path");
+
+
+module.exports = {
+
+ /**
+ * Loads the list of all available tests
+ *
+ * @param {string} rootDir
+ * @returns {Object.<string, string[]>}
+ */
+ loadAllTests: function (rootDir) {
+ var testSuite = {};
+ var self = this;
+
+ this.getAllDirectories(rootDir).forEach(
+ function (language) {
+ testSuite[language] = self.getAllFiles(path.join(rootDir, language));
+ }
+ );
+
+ return testSuite;
+ },
+
+ /**
+ * Loads the list of available tests that match the given languages
+ *
+ * @param {string} rootDir
+ * @param {string|string[]} languages
+ * @returns {Object.<string, string[]>}
+ */
+ loadSomeTests: function (rootDir, languages) {
+ var testSuite = {};
+ var self = this;
+
+ this.getSomeDirectories(rootDir, languages).forEach(
+ function (language) {
+ testSuite[language] = self.getAllFiles(path.join(rootDir, language));
+ }
+ );
+
+ return testSuite;
+ },
+
+
+ /**
+ * Returns a list of all (sub)directories (just the directory names, not full paths)
+ * in the given src directory
+ *
+ * @param {string} src
+ * @returns {Array.<string>}
+ */
+ getAllDirectories: function (src) {
+ return fs.readdirSync(src).filter(
+ function (file) {
+ return fs.statSync(path.join(src, file)).isDirectory();
+ }
+ );
+ },
+
+ /**
+ * Returns a list of all (sub)directories (just the directory names, not full paths)
+ * in the given src directory, matching the given languages
+ *
+ * @param {string} src
+ * @param {string|string[]} languages
+ * @returns {Array.<string>}
+ */
+ getSomeDirectories: function (src, languages) {
+ var self = this;
+ return fs.readdirSync(src).filter(
+ function (file) {
+ return fs.statSync(path.join(src, file)).isDirectory() && self.directoryMatches(file, languages);
+ }
+ );
+ },
+
+ /**
+ * Returns whether a directory matches one of the given languages.
+ * @param {string} directory
+ * @param {string|string[]} languages
+ */
+ directoryMatches: function (directory, languages) {
+ if (!Array.isArray(languages)) {
+ languages = [languages];
+ }
+ var dirLanguages = directory.split(/!?\+!?/);
+ return dirLanguages.some(function (lang) {
+ return languages.indexOf(lang) >= 0;
+ });
+ },
+
+
+ /**
+ * Returns a list of all full file paths to all files in the given src directory
+ *
+ * @private
+ * @param {string} src
+ * @returns {Array.<string>}
+ */
+ getAllFiles: function (src) {
+ return fs.readdirSync(src).filter(
+ function (fileName) {
+ // only find files that have the ".test" extension
+ return ".test" === path.extname(fileName) &&
+ fs.statSync(path.join(src, fileName)).isFile();
+ }
+ ).map(
+ function (fileName) {
+ return path.join(src, fileName);
+ }
+ );
+ }
+};
« 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