loadable-transformer-ts5
Version:
TypeScript custom transformer for lodable-components SSR
62 lines (61 loc) • 2.87 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var typescript_1 = __importDefault(require("typescript"));
var _1 = require("./");
function testPlugin(source) {
return typescript_1.default.transpileModule(source, {
transformers: {
before: [_1.loadableTransformer],
},
compilerOptions: {
jsx: typescript_1.default.JsxEmit.React,
target: typescript_1.default.ScriptTarget.ESNext,
module: typescript_1.default.ModuleKind.ESNext,
},
}).outputText;
}
describe('transformer', function () {
describe('simple import', function () {
it('should work with template literal', function () {
var result = testPlugin("\n loadable(() => import(`./ModA`))\n ");
expect(result).toMatchSnapshot();
});
it('should work with + concatenation', function () {
var result = testPlugin("\n loadable(() => import('./Mod' + 'A'))\n ");
expect(result).toMatchSnapshot();
});
it('should work with * in name', function () {
var result = testPlugin("\n loadable(() => import(`./foo*`))\n ");
expect(result).toMatchSnapshot();
});
it('should transform path into "chunk-friendly" name', function () {
var result = testPlugin("\n loadable(() => import('../foo/bar'))\n ");
expect(result).toMatchSnapshot();
});
describe('with "webpackChunkName" comment', function () {
it('should use it', function () {
var result = testPlugin("\n loadable(() => import(/* webpackChunkName: \"ChunkA\" */ './ModA'))\n ");
expect(result).toMatchSnapshot();
});
it('should use it even if comment is separated by ","', function () {
var result = testPlugin("\n loadable(() => import(/* webpackPrefetch: true, webpackChunkName: \"ChunkA\" */ './ModA'))\n ");
expect(result).toMatchSnapshot();
});
});
describe('without "webpackChunkName" comment', function () {
it('should add it', function () {
var result = testPlugin("\n loadable(() => import('./ModA'))\n ");
expect(result).toMatchSnapshot();
});
});
describe('in a complex promise', function () {
it('should work', function () {
var result = testPlugin("\n loadable(() => timeout(import('./ModA'), 2000))\n ");
expect(result).toMatchSnapshot();
});
});
});
});