From a4d4acd1aff3f6213d43d921624d69195c379744 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 27 Oct 2022 17:54:46 -0400 Subject: [PATCH] chore(npm): add explicit tests for `module.exports` assignment with type checking (#16435) --- cli/tests/integration/npm_tests.rs | 14 ++++++++++++++ .../npm/cjs_module_export_assignment/main.out | 3 +++ .../npm/cjs_module_export_assignment/main.ts | 6 ++++++ .../cjs_module_export_assignment_number/main.out | 3 +++ .../cjs_module_export_assignment_number/main.ts | 7 +++++++ .../1.0.0/index.d.ts | 2 ++ .../1.0.0/index.js | 1 + .../1.0.0/package.json | 5 +++++ .../cjs-module-export-assignment/1.0.0/index.d.ts | 5 +++++ .../cjs-module-export-assignment/1.0.0/index.js | 5 +++++ .../1.0.0/package.json | 5 +++++ 11 files changed, 56 insertions(+) create mode 100644 cli/tests/testdata/npm/cjs_module_export_assignment/main.out create mode 100644 cli/tests/testdata/npm/cjs_module_export_assignment/main.ts create mode 100644 cli/tests/testdata/npm/cjs_module_export_assignment_number/main.out create mode 100644 cli/tests/testdata/npm/cjs_module_export_assignment_number/main.ts create mode 100644 cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.d.ts create mode 100644 cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.js create mode 100644 cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/package.json create mode 100644 cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.d.ts create mode 100644 cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.js create mode 100644 cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/package.json diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 722cbdb391..9e3ef56782 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -110,6 +110,20 @@ itest!(child_process_fork_test { http_server: true, }); +itest!(cjs_module_export_assignment { + args: "run -A --unstable --quiet --check=all npm/cjs_module_export_assignment/main.ts", + output: "npm/cjs_module_export_assignment/main.out", + envs: env_vars(), + http_server: true, +}); + +itest!(cjs_module_export_assignment_number { + args: "run -A --unstable --quiet --check=all npm/cjs_module_export_assignment_number/main.ts", + output: "npm/cjs_module_export_assignment_number/main.out", + envs: env_vars(), + http_server: true, +}); + // FIXME(bartlomieju): npm: specifiers are not handled in dynamic imports // at the moment // itest!(dynamic_import { diff --git a/cli/tests/testdata/npm/cjs_module_export_assignment/main.out b/cli/tests/testdata/npm/cjs_module_export_assignment/main.out new file mode 100644 index 0000000000..7dfab41f1c --- /dev/null +++ b/cli/tests/testdata/npm/cjs_module_export_assignment/main.out @@ -0,0 +1,3 @@ +{ func: [Function: func] } +Module { default: { func: [Function: func] }, func: [Function: func] } +5 diff --git a/cli/tests/testdata/npm/cjs_module_export_assignment/main.ts b/cli/tests/testdata/npm/cjs_module_export_assignment/main.ts new file mode 100644 index 0000000000..93d3db1c39 --- /dev/null +++ b/cli/tests/testdata/npm/cjs_module_export_assignment/main.ts @@ -0,0 +1,6 @@ +import defaultImport, * as namespaceImport from "npm:@denotest/cjs-module-export-assignment"; +import { func } from "npm:@denotest/cjs-module-export-assignment"; + +console.log(defaultImport); +console.log(namespaceImport); +console.log(func()); diff --git a/cli/tests/testdata/npm/cjs_module_export_assignment_number/main.out b/cli/tests/testdata/npm/cjs_module_export_assignment_number/main.out new file mode 100644 index 0000000000..c808f41436 --- /dev/null +++ b/cli/tests/testdata/npm/cjs_module_export_assignment_number/main.out @@ -0,0 +1,3 @@ +5 +5 +Module { default: 5 } diff --git a/cli/tests/testdata/npm/cjs_module_export_assignment_number/main.ts b/cli/tests/testdata/npm/cjs_module_export_assignment_number/main.ts new file mode 100644 index 0000000000..aee24bf194 --- /dev/null +++ b/cli/tests/testdata/npm/cjs_module_export_assignment_number/main.ts @@ -0,0 +1,7 @@ +import defaultImport, * as namespaceImport from "npm:@denotest/cjs-module-export-assignment-number"; + +const testDefault: 5 = defaultImport; +console.log(testDefault); +const testNamespace: 5 = namespaceImport.default; +console.log(testNamespace); +console.log(namespaceImport); diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.d.ts b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.d.ts new file mode 100644 index 0000000000..0e1e0337d9 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.d.ts @@ -0,0 +1,2 @@ +declare const value = 5; +export = value; diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.js b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.js new file mode 100644 index 0000000000..f4e8d9d29a --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/index.js @@ -0,0 +1 @@ +module.exports = 5; diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/package.json new file mode 100644 index 0000000000..4b2e3a294d --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment-number/1.0.0/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/cjs-module-export-assignment-number", + "version": "1.0.0", + "types": "./index.d.ts" +} diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.d.ts b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.d.ts new file mode 100644 index 0000000000..a7b50005e6 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.d.ts @@ -0,0 +1,5 @@ +declare module ThisModule { + function func(): 5; +} + +export = ThisModule; diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.js b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.js new file mode 100644 index 0000000000..4c02858255 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/index.js @@ -0,0 +1,5 @@ +module.exports = { + func() { + return 5; + }, +}; diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/package.json new file mode 100644 index 0000000000..b8d3bbd2bd --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/cjs-module-export-assignment/1.0.0/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/cjs-module-export-assignment", + "version": "1.0.0", + "types": "./index.d.ts" +}