UNPKG

4.11 kBJavaScriptView Raw
1var convert = require("./convert");
2var amdToSlim = require("../lib/amd/slim");
3
4describe("amd - slim", function() {
5 it("anonymous and deps free", function() {
6 return convert({
7 converter: amdToSlim,
8 sourceFileName: "amd_anon_nodeps",
9 expectedFileName: "amd_nodeps_slim"
10 });
11 });
12
13 it("named and deps free", function() {
14 return convert({
15 converter: amdToSlim,
16 sourceFileName: "amd_named_nodeps",
17 expectedFileName: "amd_nodeps_slim",
18 load: { name: "amd_anon_nodeps" } // use an existing module id
19 });
20 });
21
22 it("anonymous with deps", function() {
23 return convert({
24 converter: amdToSlim,
25 sourceFileName: "amd",
26 expectedFileName: "amd_deps_slim"
27 });
28 });
29
30 it("named with deps", function() {
31 return convert({
32 converter: amdToSlim,
33 sourceFileName: "amd_named_deps",
34 expectedFileName: "amd_named_deps_slim"
35 });
36 });
37
38 it("object define shorthand", function() {
39 return convert({
40 converter: amdToSlim,
41 sourceFileName: "amd_object",
42 expectedFileName: "amd_object_slim"
43 });
44 });
45
46 it("amd simplified cjs wrapper", function() {
47 return convert({
48 converter: amdToSlim,
49 sourceFileName: "amd_cjs_wrapper",
50 expectedFileName: "amd_cjs_wrapper_slim",
51 load: { name: "amd_cjs_wrapper" }
52 });
53 });
54
55 it("named amd simplified cjs wrapper", function() {
56 return convert({
57 converter: amdToSlim,
58 sourceFileName: "amd_named_cjs_wrapper",
59 expectedFileName: "amd_cjs_wrapper_slim",
60 load: { name: "amd_cjs_wrapper" }
61 });
62 });
63
64 it("transforms dynamic imports", function() {
65 return convert({
66 converter: amdToSlim,
67 sourceFileName: "amd_dynamic_import",
68 expectedFileName: "amd_dynamic_import_slim"
69 });
70 });
71
72 it("transpile module.exports correctly", function() {
73 return convert({
74 converter: amdToSlim,
75 sourceFileName: "amd_cjs_module",
76 expectedFileName: "amd_cjs_module_slim"
77 });
78 });
79
80 it("transpiles jquery-like IIFE/AMD", function() {
81 return convert({
82 converter: amdToSlim,
83 sourceFileName: "amd_jquery",
84 expectedFileName: "amd_jquery_slim"
85 });
86 });
87
88 it("transpiles modules using CJS-like require and exports", function() {
89 return convert({
90 converter: amdToSlim,
91 sourceFileName: "amd_require_exports",
92 expectedFileName: "amd_require_exports_slim"
93 });
94 });
95
96 it("transpiles amd modules created by babel from ESM", function() {
97 return convert({
98 converter: amdToSlim,
99 sourceFileName: "amd_babel",
100 expectedFileName: "amd_babel_slim"
101 });
102 });
103
104 it("dependencies needing normalize", function() {
105 return convert({
106 converter: amdToSlim,
107 sourceFileName: "amd_needing_normalize",
108 expectedFileName: "amd_needing_normalize_slim",
109 options: {
110 normalize: function(name) {
111 var requiresPluginName = name.indexOf("!") != -1;
112 var endsWithSlash = name[name.length - 1] === "/";
113
114 // duplicates the final part of module identifier
115 // foo/bar/ -> foo/bar/bar
116 if (endsWithSlash) {
117 var parts = name.split("/");
118 parts[parts.length - 1] = parts[parts.length - 2];
119 return parts.join("/");
120
121 // returns everything after the exclamation mark as the
122 // normalized module identifier
123 } else if (requiresPluginName) {
124 return name.substr(name.indexOf("!") + 1);
125 }
126
127 return name;
128 }
129 }
130 });
131 });
132
133 it("transpiles UMD modules", function() {
134 return convert({
135 converter: amdToSlim,
136 sourceFileName: "amd_umd",
137 expectedFileName: "amd_umd_slim"
138 });
139 });
140
141 it("sets module.id when 'module' is a dependency", function() {
142 return convert({
143 converter: amdToSlim,
144 sourceFileName: "amd_module_member_expression",
145 expectedFileName: "amd_module_member_expression_slim"
146 });
147 });
148
149 it("replaces 'module' identifiers with 'stealModule'", function() {
150 return convert({
151 converter: amdToSlim,
152 sourceFileName: "amd_module_identifier",
153 expectedFileName: "amd_module_identifier_slim"
154 });
155 });
156
157 it("transpiles UMD modules with 'export' dependency", function() {
158 return convert({
159 converter: amdToSlim,
160 sourceFileName: "amd_rollup_umd",
161 expectedFileName: "amd_rollup_umd_slim"
162 });
163 });
164});