Skip to content

Commit

Permalink
Added TS test + added non-working alias tests (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Jun 4, 2019
1 parent 42271a2 commit 64efbb2
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 0 deletions.
10 changes: 10 additions & 0 deletions __tests__/__fixtures__/alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Project relative import to missing file
import { Button } from '-/components/button/Button'

// Project relative import to existing file
import { logx } from '-/testonly'

// This is probably shown as okay by TS validation, but is not supported by Babel
import 'src/testonly'

logx(Button)
10 changes: 10 additions & 0 deletions __tests__/__fixtures__/alias.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Project relative import to missing file
import { Button } from '-/components/button/Button'

// Project relative import to existing file
import { logx } from '-/testonly'

// This is probably shown as okay by TS validation, but is not supported by Babel
import 'src/testonly'

logx(Button)
13 changes: 13 additions & 0 deletions __tests__/__fixtures__/typescript.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Checks if a configuration is defined in package.json
*
* @param name Key of the configuration
* @return whether the configuration exists
*/
export const hasPackageConfig = (name: string): boolean => {
try {
return !!getPackageConfig()[name]
} catch (_) {
return false
}
}
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/target-browser-dev.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Target: Browser: Dev alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Target: Browser: Dev alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Target: Browser: Dev comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -591,3 +605,13 @@ exports[`Target: Browser: Dev require context 1`] = `
const loader = require.context(__dirname, false, /\\\\.js/);"
`;
exports[`Target: Browser: Dev typescript.tsx 1`] = `
"export const hasPackageConfig = name => {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
6 changes: 6 additions & 0 deletions __tests__/__snapshots__/target-browser-prod.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Target: Browser: Prod alias 1`] = `"import{Button}from\\"-/components/button/Button\\";import{logx}from\\"-/testonly\\";import\\"src/testonly\\";logx(Button);"`;

exports[`Target: Browser: Prod alias.tsx 1`] = `"import{Button}from\\"-/components/button/Button\\";import{logx}from\\"-/testonly\\";import\\"src/testonly\\";logx(Button);"`;

exports[`Target: Browser: Prod comments 1`] = `"import _camelCase from\\"lodash/camelCase\\";function translate(a){return _camelCase(a)}"`;

exports[`Target: Browser: Prod deadcode 1`] = `"var STATIC=!1;!1,before(),!1,after();"`;
Expand Down Expand Up @@ -51,3 +55,5 @@ exports[`Target: Browser: Prod react: jsx 1`] = `"import _jsx from\\"@babel/runt
exports[`Target: Browser: Prod react: jsx spread 1`] = `"import\\"core-js/modules/es.object.assign\\";function render(a){return React.createElement(\\"h1\\",Object.assign({className:\\"large\\"},a),\\"Hello\\")}"`;

exports[`Target: Browser: Prod require context 1`] = `"\\"test\\"===process.env.NODE_ENV&&require(\\"babel-plugin-require-context-hook/register\\")();var loader=require.context(__dirname,!1,/\\\\.js/);"`;

exports[`Target: Browser: Prod typescript.tsx 1`] = `"export var hasPackageConfig=function(a){try{return!!getPackageConfig()[a]}catch(a){return!1}};"`;
39 changes: 39 additions & 0 deletions __tests__/__snapshots__/target-node.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Target: NodeJS alias 1`] = `
"\\"use strict\\";
require(\\"src/testonly\\");
var _Button = require(\\"-/components/button/Button\\"),
_testonly = require(\\"-/testonly\\");
(0, _testonly.logx)(_Button.Button);"
`;

exports[`Target: NodeJS alias.tsx 1`] = `
"\\"use strict\\";
require(\\"src/testonly\\");
var _Button = require(\\"-/components/button/Button\\"),
_testonly = require(\\"-/testonly\\");
(0, _testonly.logx)(_Button.Button);"
`;

exports[`Target: NodeJS comments 1`] = `
"\\"use strict\\";
Expand Down Expand Up @@ -759,3 +781,20 @@ if (process.env.NODE_ENV === \\"test\\") {
const loader = __requireContext(__dirname, __dirname, false, /\\\\.js/);"
`;
exports[`Target: NodeJS typescript.tsx 1`] = `
"\\"use strict\\";
exports.__esModule = true;
exports.hasPackageConfig = void 0;
const hasPackageConfig = name => {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};
exports.hasPackageConfig = hasPackageConfig;"
`;
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/target-universal-node.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Target: Universal: Node Imports alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Target: Universal: Node Imports alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Target: Universal: Node Imports comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -676,3 +690,13 @@ exports[`Target: Universal: Node Imports require context 1`] = `
var loader = require.context(__dirname, false, /\\\\.js/);"
`;

exports[`Target: Universal: Node Imports typescript.tsx 1`] = `
"export var hasPackageConfig = function hasPackageConfig(name) {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/target-universal.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Target: Universal alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Target: Universal alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Target: Universal comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -672,3 +686,13 @@ exports[`Target: Universal require context 1`] = `
var loader = require.context(__dirname, false, /\\\\.js/);"
`;

exports[`Target: Universal typescript.tsx 1`] = `
"export var hasPackageConfig = function hasPackageConfig(name) {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/transpile-es2015.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Transpile: ES2015 alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: ES2015 alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: ES2015 comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -670,3 +684,13 @@ exports[`Transpile: ES2015 require context 1`] = `
const loader = require.context(__dirname, false, /\\\\.js/);"
`;
exports[`Transpile: ES2015 typescript.tsx 1`] = `
"export const hasPackageConfig = name => {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/transpile-es5.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Transpile: ES5 alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: ES5 alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: ES5 comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -672,3 +686,13 @@ exports[`Transpile: ES5 require context 1`] = `
var loader = require.context(__dirname, false, /\\\\.js/);"
`;

exports[`Transpile: ES5 typescript.tsx 1`] = `
"export var hasPackageConfig = function hasPackageConfig(name) {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/transpile-esm.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Transpile: ESM alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: ESM alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: ESM comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -654,3 +668,13 @@ exports[`Transpile: ESM require context 1`] = `
const loader = require.context(__dirname, false, /\\\\.js/);"
`;

exports[`Transpile: ESM typescript.tsx 1`] = `
"export const hasPackageConfig = name => {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/transpile-modern.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Transpile: Modern alias 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: Modern alias.tsx 1`] = `
"import { Button } from '-/components/button/Button';
import { logx } from '-/testonly';
import 'src/testonly';
logx(Button);"
`;

exports[`Transpile: Modern comments 1`] = `
"import _camelCase from \\"lodash/camelCase\\";
Expand Down Expand Up @@ -588,3 +602,13 @@ exports[`Transpile: Modern require context 1`] = `
const loader = require.context(__dirname, false, /\\\\.js/);"
`;

exports[`Transpile: Modern typescript.tsx 1`] = `
"export const hasPackageConfig = name => {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};"
`;
39 changes: 39 additions & 0 deletions __tests__/__snapshots__/transpile-node10.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Transpile: NodeJS v8 alias 1`] = `
"\\"use strict\\";
require(\\"src/testonly\\");
var _Button = require(\\"-/components/button/Button\\"),
_testonly = require(\\"-/testonly\\");
(0, _testonly.logx)(_Button.Button);"
`;

exports[`Transpile: NodeJS v8 alias.tsx 1`] = `
"\\"use strict\\";
require(\\"src/testonly\\");
var _Button = require(\\"-/components/button/Button\\"),
_testonly = require(\\"-/testonly\\");
(0, _testonly.logx)(_Button.Button);"
`;

exports[`Transpile: NodeJS v8 comments 1`] = `
"\\"use strict\\";
Expand Down Expand Up @@ -688,3 +710,20 @@ if (process.env.NODE_ENV === \\"test\\") {
const loader = __requireContext(__dirname, __dirname, false, /\\\\.js/);"
`;
exports[`Transpile: NodeJS v8 typescript.tsx 1`] = `
"\\"use strict\\";
exports.__esModule = true;
exports.hasPackageConfig = void 0;
const hasPackageConfig = name => {
try {
return !!getPackageConfig()[name];
} catch (_) {
return false;
}
};
exports.hasPackageConfig = hasPackageConfig;"
`;
Loading

0 comments on commit 64efbb2

Please sign in to comment.