Skip to content

Commit

Permalink
Test "chaining" of X-TypeScript-Types headers.
Browse files Browse the repository at this point in the history
Refs denoland#4184
Refs denoland#4040

In denoland#4040 we changed the way JavaScript dependencies are analysed in the
TypeScript compiler.  When we encounter a JavaScript file that doesn't
have any types, and `checkJs` is disabled, we stop the analysis.  This
caused situations where when there was a typed file, loading an
untyped file, loading a typed file, we stop the analysis.  We didn't
specifically check this "chaining" behaviour in our tests, and there
were situations in the while where this behaviour was a regression, so
this introduces test to ensure the behaviour as designed is preserved.
  • Loading branch information
kitsonk committed Mar 17, 2020
1 parent f9557a4 commit 6f48fba
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,11 @@ itest!(type_directives_02 {
output: "type_directives_02.ts.out",
});

itest!(type_directives_03 {
args: "run --reload -L debug type_directives_03.ts",
output: "type_directives_03.ts.out",
});

itest!(types {
args: "types",
output: "types.out",
Expand Down
3 changes: 3 additions & 0 deletions cli/tests/type_directives_03.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as foo from "http://127.0.0.1:4545/xt001.js";

console.log(foo.foo);
5 changes: 5 additions & 0 deletions cli/tests/type_directives_03.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[WILDCARD]
DEBUG TS - compiler::host.getSourceFile http://127.0.0.1:4545/xt001.d.ts
[WILDCARD]
DEBUG TS - compiler::host.getSourceFile http://127.0.0.1:4545/xt002.d.ts
[WILDCARD]
34 changes: 34 additions & 0 deletions tools/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,40 @@ def do_GET(self):
self.wfile.write(bytes("export const foo: 'foo';"))
return

if "xt001.js" in self.path:
self.protocol_version = "HTTP/1.1"
self.send_response(200, 'OK')
self.send_header('Content-type', 'application/javascript')
self.send_header('X-TypeScript-Types', './xt001.d.ts')
self.end_headers()
self.wfile.write(bytes("export * from './xt002.js';"))
return

if "xt001.d.ts" in self.path:
self.protocol_version = "HTTP/1.1"
self.send_response(200, 'OK')
self.send_header('Content-type', 'application/typescript')
self.end_headers()
self.wfile.write(bytes("export * from './xt002.js';"))
return

if "xt002.js" in self.path:
self.protocol_version = "HTTP/1.1"
self.send_response(200, 'OK')
self.send_header('Content-type', 'application/javascript')
self.send_header('X-TypeScript-Types', './xt002.d.ts')
self.end_headers()
self.wfile.write(bytes("export const foo = 'foo';"))
return

if "xt002.d.ts" in self.path:
self.protocol_version = "HTTP/1.1"
self.send_response(200, 'OK')
self.send_header('Content-type', 'application/typescript')
self.end_headers()
self.wfile.write(bytes("export const foo: 'foo';"))
return

if "referenceTypes.js" in self.path:
self.protocol_version = "HTTP/1.1"
self.send_response(200, 'OK')
Expand Down

0 comments on commit 6f48fba

Please sign in to comment.