-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add
parse-tsconfig
spec (#397)
* test: add `parse-tsconfig` spec - test passing tsconfig, buggy tsconfig, non-existent tsconfig, and not a tsconfig - clean: "failed to read" error will never happen as we already checked for existence of the file earlier - so remove the `undefined` check and instead use a non-null assertion (plus a comment explaining it) - refactor: move the integration test for tsconfig error into this unit test instead - faster / more efficient / more precise - refactor: split out a `makeOptions` func that creates default plugin options to use in tests - similar to `makeStubbedContext` * fix windows test by normalizing Co-authored-by: Eugene Zolenko <zolenkoe@gmail.com>
- Loading branch information
Showing
5 changed files
with
80 additions
and
38 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,32 @@ | ||
import * as ts from "typescript"; | ||
|
||
import { setTypescriptModule } from "../../src/tsproxy"; | ||
import { IOptions } from "../../src/ioptions"; | ||
|
||
setTypescriptModule(ts); | ||
|
||
export function makeOptions(cacheDir: string, cwd: string): IOptions { | ||
return { | ||
include: ["*.ts+(|x)", "**/*.ts+(|x)"], | ||
exclude: ["*.d.ts", "**/*.d.ts"], | ||
check: false, | ||
verbosity: 5, | ||
clean: false, | ||
cacheRoot: cacheDir, | ||
cwd, | ||
abortOnError: false, | ||
rollupCommonJSResolveHack: false, | ||
typescript: ts, | ||
objectHashIgnoreUnknownHack: false, | ||
tsconfigOverride: null, | ||
useTsconfigDeclarationDir: false, | ||
tsconfigDefaults: null, | ||
sourceMapCallback: (id: string, map: string): void => { | ||
console.log(id + map); | ||
}, | ||
transformers: [(ls: ts.LanguageService) => { | ||
console.log(ls); | ||
return {}; | ||
}], | ||
}; | ||
} |
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
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
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,45 @@ | ||
import { test, expect } from "@jest/globals"; | ||
import * as path from "path"; | ||
import { normalizePath as normalize } from "@rollup/pluginutils"; | ||
|
||
import { makeOptions } from "./fixtures/options"; | ||
import { makeStubbedContext } from "./fixtures/context"; | ||
import { parseTsConfig } from "../src/parse-tsconfig"; | ||
|
||
const local = (x: string) => normalize(path.resolve(__dirname, x)); | ||
|
||
const defaultOpts = makeOptions("", ""); | ||
const stubbedContext = makeStubbedContext({}); | ||
|
||
test("parseTsConfig", () => { | ||
expect(() => parseTsConfig(stubbedContext, defaultOpts)).not.toThrow(); | ||
}); | ||
|
||
test("parseTsConfig - tsconfig errors", () => { | ||
const data = { error: "" }; | ||
|
||
// should not throw when the tsconfig is buggy, but should still print an error (below) | ||
expect(() => parseTsConfig(makeStubbedContext(data), { | ||
...defaultOpts, | ||
tsconfigOverride: { | ||
include: "should-be-an-array", | ||
}, | ||
})).not.toThrow(); | ||
expect(data.error).toMatch("Compiler option 'include' requires a value of type Array"); | ||
}); | ||
|
||
test("parseTsConfig - failed to open", () => { | ||
expect(() => parseTsConfig(stubbedContext, { | ||
...defaultOpts, | ||
tsconfig: "non-existent-tsconfig", | ||
})).toThrow("rpt2: failed to open 'non-existent-tsconfig'"); | ||
}); | ||
|
||
test("parseTsConfig - failed to parse", () => { | ||
const notTsConfigPath = local("fixtures/options.ts"); // a TS file should fail to parse | ||
|
||
expect(() => parseTsConfig(stubbedContext, { | ||
...defaultOpts, | ||
tsconfig: notTsConfigPath, | ||
})).toThrow(`rpt2: failed to parse '${notTsConfigPath}'`); | ||
}); |
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