-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(intelli-espower-loader): add default patterns
- Loading branch information
Showing
5 changed files
with
106 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,8 @@ | ||
"use strict"; | ||
var fs = require("fs"); | ||
var assert = require("assert"); | ||
var pather = require("path"); | ||
var normalizeDir = require("./lib/normalize-dir"); | ||
var packageName = require("./package.json").name; | ||
|
||
function findPackageDir(paths) { | ||
if (!paths) { | ||
return null; | ||
} | ||
for (var i = 0; i < paths.length; ++i) { | ||
var dir = pather.dirname(paths[i]); | ||
var dirName = dir.split(pather.sep).pop(); | ||
if (dirName !== packageName && fs.existsSync(pather.join(dir, 'package.json'))) { | ||
return dir; | ||
} | ||
} | ||
} | ||
function getPackageJSON() { | ||
var dir = findPackageDir(module.paths); | ||
assert(dir, "package.json is not found"); | ||
return require(pather.resolve(dir, "package.json")); | ||
} | ||
function getTestDirFromPkg(pkg) { | ||
var directories = pkg.directories; | ||
assert.equal(typeof directories, "object", 'You should setting `directories : { test : "test/" }`'); | ||
assert.equal(typeof directories.test, "string", 'You should setting `directories : { test : "test/" }`'); | ||
return directories.test; | ||
} | ||
var pkg = getPackageJSON(); | ||
var testDirectory = getTestDirFromPkg(pkg); | ||
var pkg = require("./lib/get-package-json")(module.paths); | ||
var testDirectory = require("./lib/get-test-dir")(pkg); | ||
require('espower-loader')({ | ||
cwd: process.cwd(), | ||
pattern: normalizeDir(testDirectory) + "**" + pather.sep + "*.js" | ||
pattern: testDirectory + "**" + pather.sep + "*.js" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
var fs = require("fs"); | ||
var assert = require("assert"); | ||
var pather = require("path"); | ||
var packageName = require("../package.json").name; | ||
|
||
function findPackageDir(paths) { | ||
if (!paths) { | ||
return null; | ||
} | ||
for (var i = 0; i < paths.length; ++i) { | ||
var dir = pather.dirname(paths[i]); | ||
var dirName = dir.split(pather.sep).pop(); | ||
if (dirName !== packageName && fs.existsSync(pather.join(dir, 'package.json'))) { | ||
return dir; | ||
} | ||
} | ||
} | ||
/** | ||
* @param {string[]} paths the paths for look-up | ||
* @returns {*} | ||
*/ | ||
function getPackageJSON(paths) { | ||
var dir = findPackageDir(paths); | ||
assert(dir, "package.json is not found"); | ||
return require(pather.resolve(dir, "package.json")); | ||
} | ||
module.exports = getPackageJSON; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
var normalizeDir = require("./normalize-dir"); | ||
/** | ||
* Return `dir/` string | ||
* always suffix with `/` | ||
* @param {object} pkg | ||
* @returns {string} | ||
*/ | ||
function getTestDirFromPkg(pkg) { | ||
if (pkg && | ||
typeof pkg.directories === 'object' && | ||
typeof pkg.directories.test === 'string') { | ||
return normalizeDir(pkg.directories.test); | ||
} | ||
return "test/"; // default value | ||
} | ||
|
||
module.exports = getTestDirFromPkg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
var assert = require("assert"); | ||
var getTestDir = require("../lib/get-test-dir"); | ||
describe("get-test-dir-test", function () { | ||
context("when `pkg.directories.test` is not found", function () { | ||
it("should return 'test/'", function () { | ||
var dir = getTestDir({ | ||
"directories": {} | ||
}); | ||
assert.equal(dir, "test/"); | ||
}); | ||
}); | ||
context("when `pkg.directories.test` is set", function () { | ||
it("should return 'test/'", function () { | ||
var dir = getTestDir({ | ||
"directories": { | ||
"test": "user-dir" | ||
} | ||
}); | ||
assert.equal(dir, "user-dir/"); | ||
}); | ||
}); | ||
}); |