ts-node-test-register
Version:
Load from `test/tsconfig.json` with ts-node.
72 lines • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findTestTsconfigJSON = exports.resolvePath = exports.getTestDirectoryInPackageJSON = void 0;
var path = require("path");
var fs = require("fs");
var readPkg = require("read-pkg");
/**
* get "test" dir
* "directories": {
* "lib": "lib",
* "test": "test"
* },
*
* @param {string} currentDir
*/
var getTestDirectoryInPackageJSON = function (currentDir) {
if (!currentDir) {
return;
}
var pkg = readPkg.sync({
cwd: currentDir
});
if (!pkg) {
return;
}
if (!pkg.directories) {
return;
}
if (typeof pkg.directories.test !== "string") {
return;
}
return pkg.directories.test;
};
exports.getTestDirectoryInPackageJSON = getTestDirectoryInPackageJSON;
var resolvePath = function (filePathList) {
for (var i = 0; i < filePathList.length; i++) {
var filePath = filePathList[i];
if (fs.existsSync(filePath)) {
return filePath;
}
}
return undefined;
};
exports.resolvePath = resolvePath;
/**
* Find tsconfig.json by follows
*
* 1. test/tsconfig.test.json
* 2. test/tsconfig.json
* 3. tsconfig.test.json
* 4. tsconfig.json
*
* @param {string} testDirectoryName
* @param {string} baseDirectory
* @returns {string | undefined}
*/
var findTestTsconfigJSON = function (testDirectoryName, baseDirectory) {
if (testDirectoryName === void 0) { testDirectoryName = "test"; }
if (baseDirectory === void 0) { baseDirectory = process.cwd(); }
var testTsconfigJsonInTestDir = path.join(baseDirectory, testDirectoryName, "tsconfig.test.json");
var tsconfigJsonInTestDir = path.join(baseDirectory, testDirectoryName, "tsconfig.json");
var testTsconfigJsonInCurrentDir = path.join(baseDirectory, "tsconfig.test.json");
var tsconfigInCurrentDir = path.join(baseDirectory, "tsconfig.json");
return exports.resolvePath([
testTsconfigJsonInTestDir,
tsconfigJsonInTestDir,
testTsconfigJsonInCurrentDir,
tsconfigInCurrentDir
]);
};
exports.findTestTsconfigJSON = findTestTsconfigJSON;
//# sourceMappingURL=find-test-tsconfig.js.map