Skip to content

Commit

Permalink
[WIP] Various test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Dec 9, 2019
1 parent 27aedbc commit f24c9fb
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
18 changes: 8 additions & 10 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,12 @@ function cache(

function processConfigureResponse(
configResult: ConfigureResponse,
configPath = ""
configPath: string
): ts.Diagnostic[] | undefined {
const { ignoredOptions, diagnostics } = configResult;
if (ignoredOptions) {
console.warn(
(configPath
? yellow(`Unsupported compiler options in "${configPath}"\n`)
: yellow("Unsupported compiler options.")) +
yellow(`Unsupported compiler options in "${configPath}"\n`) +
cyan(` The following options were ignored:\n`) +
` ${ignoredOptions.map((value): string => bold(value)).join(", ")}`
);
Expand Down Expand Up @@ -990,16 +988,16 @@ self.compilerMain = function compilerMain(): void {
}
// we only support single root names for bundles
assert(rootNames.length === 1);
const bundle = buildBundle(rootNames[0], data, sourceFiles);
const out = buildBundle(rootNames[0], data, sourceFiles);
if (outFile) {
const encodedData = encoder.encode(bundle);
console.warn(`Emitting bundle to "${fileName}"`);
writeFileSync(fileName, encodedData);
const encodedData = encoder.encode(out);
console.warn(`Emitting bundle to "${outFile}"`);
writeFileSync(outFile, encodedData);
console.warn(
`${util.humanFileSize(encodedData.length)} emitted.`
);
} else {
console.log(bundle);
console.log(out);
}
}
};
Expand All @@ -1011,7 +1009,7 @@ self.compilerMain = function compilerMain(): void {
// if there is a configuration supplied, we need to parse that
if (config && config.length && configPath) {
const configResult = host.configure(configPath, config);
diagnostics = processConfigureResponse(configResult);
diagnostics = processConfigureResponse(configResult, configPath);
}

let emitSkipped = true;
Expand Down
10 changes: 8 additions & 2 deletions cli/js/compiler_api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

// This file contains the runtime APIs which will dispatch work to the internal
// compiler within Deno.

import { Diagnostic } from "./diagnostics.ts";
import * as dispatch from "./dispatch.ts";
import { sendAsync, sendSync } from "./dispatch_json.ts";
Expand Down Expand Up @@ -284,7 +287,7 @@ export function transpileOnly(
sources: Record<string, string>,
options?: CompilerOptions
): Promise<Record<string, TranspileOnlyResult>> {
util.log("Deno.transpileOnly");
util.log("Deno.transpileOnly", { sources: Object.keys(sources), options });
const payload = {
sources,
options: options ? JSON.stringify(options) : undefined
Expand Down Expand Up @@ -315,7 +318,10 @@ export function transpileOnlySync(
sources: Record<string, string>,
options?: CompilerOptions
): Record<string, TranspileOnlyResult> {
util.log("Deno.transpileOnlySync");
util.log("Deno.transpileOnlySync", {
sources: Object.keys(sources),
options
});
return sendSync(dispatch.OP_TRANSPILE, {
sources,
options: options ? JSON.stringify(options) : undefined
Expand Down
15 changes: 13 additions & 2 deletions cli/js/compiler_api_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

import { assert, assertEquals, test } from "./test_util.ts";

const { compile, compileSync } = Deno;
const {
compile
// compileSync,
// transpileOnly,
// transpileOnlySync,
// bundle,
// bundleSync
} = Deno;

test(async function compilerApiCompileSources() {
const result = await Deno.compile("/foo.ts", {
const [diagnostics, actual] = await compile("/foo.ts", {
"/foo.ts": `console.log("foo");\nexport {}\n`
});
assert(diagnostics == null);
assert(actual);
assertEquals(Object.keys(actual).length, 2);
});
9 changes: 6 additions & 3 deletions cli/tests/error_011_bad_module_specifier.ts.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_011_bad_module_specifier.ts"
[WILDCARD]dispatch_json.ts:[WILDCARD]
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
at DenoError ($deno$/errors.ts:[WILDCARD])
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
at resolveModules ($deno$/compiler.ts:[WILDCARD])
at processImports ($deno$/compiler.ts:[WILDCARD])
at processImports ($deno$/compiler.ts:[WILDCARD])
9 changes: 6 additions & 3 deletions cli/tests/error_012_bad_dynamic_import_specifier.ts.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts"
[WILDCARD]dispatch_json.ts:[WILDCARD]
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
at DenoError ($deno$/errors.ts:[WILDCARD])
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
at resolveModules ($deno$/compiler.ts:[WILDCARD])
at processImports ($deno$/compiler.ts:[WILDCARD])
at processImports ($deno$/compiler.ts:[WILDCARD])
9 changes: 6 additions & 3 deletions cli/tests/error_type_definitions.ts.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "baz" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/type_definitions/bar.d.ts"
[WILDCARD]dispatch_json.ts:[WILDCARD]
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
at DenoError ($deno$/errors.ts:[WILDCARD])
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
at resolveModules ($deno$/compiler.ts:[WILDCARD])
at processImports ($deno$/compiler.ts:[WILDCARD])
at processImports ($deno$/compiler.ts:[WILDCARD])

0 comments on commit f24c9fb

Please sign in to comment.