2015-12-03 19:44:24 +01:00
|
|
|
/// <reference path="..\..\..\src\harness\external\mocha.d.ts" />
|
|
|
|
/// <reference path="..\..\..\src\harness\harness.ts" />
|
2015-12-17 00:49:31 +01:00
|
|
|
/// <reference path="..\..\..\src\harness\virtualFileSystem.ts" />
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-07 23:58:13 +01:00
|
|
|
namespace ts {
|
2015-12-15 00:21:12 +01:00
|
|
|
class MockParseConfigHost extends Utils.VirtualFileSystem implements ParseConfigHost {
|
|
|
|
constructor(currentDirectory: string, ignoreCase: boolean, files: string[]) {
|
|
|
|
super(currentDirectory, ignoreCase);
|
|
|
|
for (const file of files) {
|
|
|
|
this.addFile(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readDirectory(path: string, extensions: string[], excludes: string[], includes: string[]) {
|
|
|
|
return matchFiles(path, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, (path: string) => this.getAccessibleFileSystemEntries(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
getAccessibleFileSystemEntries(path: string) {
|
|
|
|
const entry = this.traversePath(path);
|
|
|
|
if (entry && entry.isDirectory()) {
|
|
|
|
const directory = <Utils.VirtualDirectory>entry;
|
|
|
|
return {
|
|
|
|
files: map(directory.getFiles(), f => f.name),
|
|
|
|
directories: map(directory.getDirectories(), d => d.name)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return { files: [], directories: [] };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 23:58:13 +01:00
|
|
|
const caseInsensitiveBasePath = "c:/dev/";
|
2015-12-15 00:21:12 +01:00
|
|
|
const caseInsensitiveHost = new MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/a.d.ts",
|
|
|
|
"c:/dev/a.js",
|
|
|
|
"c:/dev/b.ts",
|
|
|
|
"c:/dev/b.js",
|
|
|
|
"c:/dev/c.d.ts",
|
|
|
|
"c:/dev/z/a.ts",
|
|
|
|
"c:/dev/z/abz.ts",
|
|
|
|
"c:/dev/z/aba.ts",
|
|
|
|
"c:/dev/z/b.ts",
|
|
|
|
"c:/dev/z/bbz.ts",
|
|
|
|
"c:/dev/z/bba.ts",
|
|
|
|
"c:/dev/x/a.ts",
|
|
|
|
"c:/dev/x/aa.ts",
|
|
|
|
"c:/dev/x/b.ts",
|
|
|
|
"c:/dev/x/y/a.ts",
|
|
|
|
"c:/dev/x/y/b.ts",
|
|
|
|
"c:/dev/js/a.js",
|
|
|
|
"c:/dev/js/b.js",
|
|
|
|
"c:/ext/ext.ts"
|
2015-12-07 23:58:13 +01:00
|
|
|
]);
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-07 23:58:13 +01:00
|
|
|
const caseSensitiveBasePath = "/dev/";
|
2015-12-15 00:21:12 +01:00
|
|
|
const caseSensitiveHost = new MockParseConfigHost(caseSensitiveBasePath, /*useCaseSensitiveFileNames*/ true, [
|
|
|
|
"/dev/a.ts",
|
|
|
|
"/dev/a.d.ts",
|
|
|
|
"/dev/a.js",
|
|
|
|
"/dev/b.ts",
|
|
|
|
"/dev/b.js",
|
|
|
|
"/dev/A.ts",
|
|
|
|
"/dev/B.ts",
|
|
|
|
"/dev/c.d.ts",
|
|
|
|
"/dev/z/a.ts",
|
|
|
|
"/dev/z/abz.ts",
|
|
|
|
"/dev/z/aba.ts",
|
|
|
|
"/dev/z/b.ts",
|
|
|
|
"/dev/z/bbz.ts",
|
|
|
|
"/dev/z/bba.ts",
|
|
|
|
"/dev/x/a.ts",
|
|
|
|
"/dev/x/b.ts",
|
|
|
|
"/dev/x/y/a.ts",
|
|
|
|
"/dev/x/y/b.ts",
|
|
|
|
"/dev/js/a.js",
|
|
|
|
"/dev/js/b.js",
|
2015-12-07 23:58:13 +01:00
|
|
|
]);
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
const caseInsensitiveMixedExtensionHost = new MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/a.d.ts",
|
|
|
|
"c:/dev/a.js",
|
|
|
|
"c:/dev/b.tsx",
|
|
|
|
"c:/dev/b.d.ts",
|
|
|
|
"c:/dev/b.jsx",
|
|
|
|
"c:/dev/c.tsx",
|
|
|
|
"c:/dev/c.js",
|
|
|
|
"c:/dev/d.js",
|
|
|
|
"c:/dev/e.jsx",
|
|
|
|
"c:/dev/f.other"
|
2015-12-07 23:58:13 +01:00
|
|
|
]);
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-17 00:49:31 +01:00
|
|
|
describe("matchFiles", () => {
|
2015-12-07 23:58:13 +01:00
|
|
|
describe("with literal file list", () => {
|
|
|
|
it("without exclusions", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
files: [
|
|
|
|
"a.ts",
|
|
|
|
"b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("missing files are still present", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
files: [
|
|
|
|
"z.ts",
|
|
|
|
"x.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/z.ts",
|
|
|
|
"c:/dev/x.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("are not removed due to excludes", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
files: [
|
|
|
|
"a.ts",
|
|
|
|
"b.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
2015-12-03 19:44:24 +01:00
|
|
|
});
|
2015-12-07 23:58:13 +01:00
|
|
|
|
|
|
|
describe("with literal include list", () => {
|
|
|
|
it("without exclusions", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"a.ts",
|
|
|
|
"b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with non .ts file extensions are excluded", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"a.js",
|
|
|
|
"b.js"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with missing files are excluded", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"z.ts",
|
|
|
|
"x.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with literal excludes", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"a.ts",
|
|
|
|
"b.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with wildcard excludes", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"a.ts",
|
|
|
|
"b.ts",
|
|
|
|
"z/a.ts",
|
|
|
|
"z/abz.ts",
|
|
|
|
"z/aba.ts",
|
|
|
|
"x/b.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"*.ts",
|
|
|
|
"z/??z.ts",
|
|
|
|
"*/b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/z/a.ts",
|
|
|
|
"c:/dev/z/aba.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with recursive excludes", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"a.ts",
|
|
|
|
"b.ts",
|
|
|
|
"x/a.ts",
|
|
|
|
"x/b.ts",
|
|
|
|
"x/y/a.ts",
|
|
|
|
"x/y/b.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"**/b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/x/a.ts",
|
|
|
|
"c:/dev/x/y/a.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with case sensitive exclude", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"B.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"**/b.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"/dev/B.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseSensitiveHost, caseSensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
2015-12-03 19:44:24 +01:00
|
|
|
});
|
2015-12-07 23:58:13 +01:00
|
|
|
|
|
|
|
describe("with wildcard include list", () => {
|
|
|
|
it("same named declarations are excluded", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"*.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts",
|
|
|
|
"c:/dev/c.d.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.None
|
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("`*` matches only ts files", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"*"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts",
|
|
|
|
"c:/dev/c.d.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.None
|
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("`?` matches only a single character", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"x/?.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/x/a.ts",
|
|
|
|
"c:/dev/x/b.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev/x": ts.WatchDirectoryFlags.None
|
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with recursive directory", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**/a.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/x/a.ts",
|
|
|
|
"c:/dev/x/y/a.ts",
|
|
|
|
"c:/dev/z/a.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("case sensitive", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**/A.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"/dev/A.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
|
|
|
"/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseSensitiveHost, caseSensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with missing files are excluded", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"*/z.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {
|
2015-12-15 00:21:12 +01:00
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
2015-12-07 23:58:13 +01:00
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("always include literal files", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
files: [
|
|
|
|
"a.ts"
|
|
|
|
],
|
|
|
|
include: [
|
|
|
|
"*/z.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"**/a.ts"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
2015-12-15 00:21:12 +01:00
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
2015-12-07 23:58:13 +01:00
|
|
|
},
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("exclude folders", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**/*"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"z",
|
|
|
|
"x"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts",
|
|
|
|
"c:/dev/c.d.ts"
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("exclude .js files when allowJs=false", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
compilerOptions: {
|
|
|
|
allowJs: false
|
|
|
|
},
|
|
|
|
include: [
|
|
|
|
"js/*"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {
|
|
|
|
allowJs: false
|
|
|
|
},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev/js": ts.WatchDirectoryFlags.None
|
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("include .js files when allowJs=true", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
compilerOptions: {
|
|
|
|
allowJs: true
|
|
|
|
},
|
|
|
|
include: [
|
|
|
|
"js/*"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {
|
|
|
|
allowJs: true
|
|
|
|
},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/js/a.js",
|
|
|
|
"c:/dev/js/b.js"
|
|
|
|
],
|
2015-12-07 23:58:13 +01:00
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev/js": ts.WatchDirectoryFlags.None
|
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
2015-12-15 00:21:12 +01:00
|
|
|
it("include paths outside of the project", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"*",
|
|
|
|
"c:/ext/*"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
2015-12-15 00:21:12 +01:00
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.ts",
|
|
|
|
"c:/dev/c.d.ts",
|
|
|
|
"c:/ext/ext.ts",
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.None,
|
|
|
|
"c:/ext": ts.WatchDirectoryFlags.None
|
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-15 00:21:12 +01:00
|
|
|
});
|
2015-12-07 23:58:13 +01:00
|
|
|
it("with jsx=none, allowJs=false", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
compilerOptions: {
|
|
|
|
allowJs: false
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {
|
|
|
|
allowJs: false
|
|
|
|
},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.tsx",
|
|
|
|
"c:/dev/c.tsx",
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with jsx=preserve, allowJs=false", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
compilerOptions: {
|
|
|
|
jsx: "preserve",
|
|
|
|
allowJs: false
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {
|
|
|
|
jsx: ts.JsxEmit.Preserve,
|
|
|
|
allowJs: false
|
|
|
|
},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.tsx",
|
|
|
|
"c:/dev/c.tsx",
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with jsx=none, allowJs=true", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
compilerOptions: {
|
|
|
|
allowJs: true
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {
|
|
|
|
allowJs: true
|
|
|
|
},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.tsx",
|
|
|
|
"c:/dev/c.tsx",
|
|
|
|
"c:/dev/d.js",
|
|
|
|
"c:/dev/e.jsx",
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
|
|
|
it("with jsx=preserve, allowJs=true", () => {
|
2015-12-16 22:42:17 +01:00
|
|
|
const json = {
|
|
|
|
compilerOptions: {
|
|
|
|
jsx: "preserve",
|
|
|
|
allowJs: true
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
};
|
2015-12-16 22:42:17 +01:00
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {
|
|
|
|
jsx: ts.JsxEmit.Preserve,
|
|
|
|
allowJs: true
|
|
|
|
},
|
|
|
|
errors: [],
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/b.tsx",
|
|
|
|
"c:/dev/c.tsx",
|
|
|
|
"c:/dev/d.js",
|
|
|
|
"c:/dev/e.jsx",
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-16 22:42:17 +01:00
|
|
|
});
|
|
|
|
describe("with trailing recursive directory", () => {
|
|
|
|
it("in includes", () => {
|
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [
|
|
|
|
ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, "**")
|
|
|
|
],
|
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-16 22:42:17 +01:00
|
|
|
});
|
|
|
|
it("in excludes", () => {
|
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**/*"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"**"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [],
|
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-16 22:42:17 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("with multiple recursive directory patterns", () => {
|
|
|
|
it("in includes", () => {
|
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**/x/**/*"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [
|
|
|
|
ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, "**/x/**/*")
|
|
|
|
],
|
|
|
|
fileNames: [],
|
|
|
|
wildcardDirectories: {}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-16 22:42:17 +01:00
|
|
|
});
|
|
|
|
it("in excludes", () => {
|
|
|
|
const json = {
|
|
|
|
include: [
|
|
|
|
"**/a.ts"
|
|
|
|
],
|
|
|
|
exclude: [
|
|
|
|
"**/x/**"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const expected: ts.ParsedCommandLine = {
|
|
|
|
options: {},
|
|
|
|
errors: [
|
|
|
|
ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, "**/x/**")
|
|
|
|
],
|
|
|
|
fileNames: [
|
|
|
|
"c:/dev/a.ts",
|
|
|
|
"c:/dev/x/a.ts",
|
|
|
|
"c:/dev/x/y/a.ts",
|
|
|
|
"c:/dev/z/a.ts"
|
|
|
|
],
|
|
|
|
wildcardDirectories: {
|
|
|
|
"c:/dev": ts.WatchDirectoryFlags.Recursive
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath);
|
2016-05-26 02:06:50 +02:00
|
|
|
assert.deepEqual(actual.fileNames, expected.fileNames);
|
|
|
|
assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories);
|
|
|
|
assert.deepEqual(actual.errors, expected.errors);
|
2015-12-16 22:42:17 +01:00
|
|
|
});
|
2015-12-07 23:58:13 +01:00
|
|
|
});
|
2015-12-03 19:44:24 +01:00
|
|
|
});
|
|
|
|
});
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|