From 1f535d772eb720a5bd6142059cca904b0fef1b3e Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Sun, 29 Sep 2019 16:29:42 -0400 Subject: [PATCH] chore: Add a couple tsc tests (#1183) --- tap-snapshots/test-tsc.js-TAP.test.js | 26 +++++++++++++++++++++++++ test/fixtures/tsc/.npmrc | 1 + test/fixtures/tsc/mapping.js | 16 +++++++++++++++ test/fixtures/tsc/mapping.js.map | 1 + test/fixtures/tsc/mapping.ts | 8 ++++++++ test/fixtures/tsc/package.json | 15 ++++++++++++++ test/fixtures/tsc/tsconfig.json | 8 ++++++++ test/tsc.js | 28 +++++++++++++++++++++++++++ 8 files changed, 103 insertions(+) create mode 100644 tap-snapshots/test-tsc.js-TAP.test.js create mode 100644 test/fixtures/tsc/.npmrc create mode 100644 test/fixtures/tsc/mapping.js create mode 100644 test/fixtures/tsc/mapping.js.map create mode 100644 test/fixtures/tsc/mapping.ts create mode 100644 test/fixtures/tsc/package.json create mode 100644 test/fixtures/tsc/tsconfig.json create mode 100644 test/tsc.js diff --git a/tap-snapshots/test-tsc.js-TAP.test.js b/tap-snapshots/test-tsc.js-TAP.test.js new file mode 100644 index 000000000..2a2ea9b91 --- /dev/null +++ b/tap-snapshots/test-tsc.js-TAP.test.js @@ -0,0 +1,26 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/tsc.js TAP ignore source-map > stdout 1`] = ` +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 38.46 | 57.14 | 66.67 | 50 | + mapping.js | 38.46 | 57.14 | 66.67 | 50 | 3,4,5,6,8 +------------|---------|----------|---------|---------|------------------- + +` + +exports[`test/tsc.js TAP reads source-map > stdout 1`] = ` +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + mapping.ts | 100 | 100 | 100 | 100 | +------------|---------|----------|---------|---------|------------------- + +` diff --git a/test/fixtures/tsc/.npmrc b/test/fixtures/tsc/.npmrc new file mode 100644 index 000000000..43c97e719 --- /dev/null +++ b/test/fixtures/tsc/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/test/fixtures/tsc/mapping.js b/test/fixtures/tsc/mapping.js new file mode 100644 index 000000000..7abbab206 --- /dev/null +++ b/test/fixtures/tsc/mapping.js @@ -0,0 +1,16 @@ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +function munge1(obj) { + return __assign({ name: 'munge1' }, obj); +} +munge1({}); +//# sourceMappingURL=mapping.js.map \ No newline at end of file diff --git a/test/fixtures/tsc/mapping.js.map b/test/fixtures/tsc/mapping.js.map new file mode 100644 index 000000000..e89dc7a6a --- /dev/null +++ b/test/fixtures/tsc/mapping.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mapping.js","sourceRoot":"","sources":["mapping.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,SAAS,MAAM,CAAE,GAAW;IAC1B,kBACE,IAAI,EAAE,QAAQ,IACX,GAAG,EACN;AACJ,CAAC;AAED,MAAM,CAAC,EAAE,CAAC,CAAA"} \ No newline at end of file diff --git a/test/fixtures/tsc/mapping.ts b/test/fixtures/tsc/mapping.ts new file mode 100644 index 000000000..bb37a9db1 --- /dev/null +++ b/test/fixtures/tsc/mapping.ts @@ -0,0 +1,8 @@ +function munge1 (obj: Object) { + return { + name: 'munge1', + ...obj + }; +} + +munge1({}) diff --git a/test/fixtures/tsc/package.json b/test/fixtures/tsc/package.json new file mode 100644 index 000000000..59eeac666 --- /dev/null +++ b/test/fixtures/tsc/package.json @@ -0,0 +1,15 @@ +{ + "private": true, + "scripts": { + "postinstall": "tsc" + }, + "devDependencies": { + "typescript": "^3.6.3" + }, + "nyc": { + "reporter": [ + "text", + "html" + ] + } +} diff --git a/test/fixtures/tsc/tsconfig.json b/test/fixtures/tsc/tsconfig.json new file mode 100644 index 000000000..f0e13c61b --- /dev/null +++ b/test/fixtures/tsc/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "sourceMap": true + }, + "files": [ + "mapping.ts" + ] +} diff --git a/test/tsc.js b/test/tsc.js new file mode 100644 index 000000000..d61dafa53 --- /dev/null +++ b/test/tsc.js @@ -0,0 +1,28 @@ +'use strict' + +const path = require('path') +const t = require('tap') + +const { testSuccess } = require('./helpers') +const fixturesTSC = path.resolve(__dirname, 'fixtures/tsc') + +t.test('reads source-map', t => testSuccess(t, { + cwd: fixturesTSC, + args: [ + '--produce-source-map=true', + '--cache=false', + process.execPath, + 'mapping.js' + ] +})) + +t.test('ignore source-map', t => testSuccess(t, { + cwd: fixturesTSC, + args: [ + '--produce-source-map=true', + '--no-source-map', + '--cache=false', + process.execPath, + 'mapping.js' + ] +}))