Skip to content

Commit ec9994f

Browse files
refactor: test (#209)
1 parent dbd952c commit ec9994f

File tree

6 files changed

+122
-141
lines changed

6 files changed

+122
-141
lines changed

.eslintrc

Lines changed: 0 additions & 24 deletions
This file was deleted.

.npmignore

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/cjs.test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import loader from '../src';
2-
import CJSLoader from '../src/cjs';
1+
import src from '../src';
2+
import cjs from '../src/cjs';
33

4-
describe('CJS', () => {
5-
it('should exported loader', () => {
6-
expect(CJSLoader).toEqual(loader);
4+
describe('cjs', () => {
5+
it('should exported', () => {
6+
expect(cjs).toEqual(src);
7+
});
8+
9+
it('should export "raw" flag', () => {
10+
expect(cjs.raw).toEqual(true);
711
});
812
});

test/loaderTest.test.js renamed to test/loader.test.js

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -84,47 +84,7 @@ describe('loader', () => {
8484
`${GET_URL_CODE}module.exports = "<h3>#{number} {customer}</h3>\\n<p> {title} </p>";`
8585
);
8686
});
87-
it('should minimize', () => {
88-
const result = loader.call(
89-
{
90-
query: '?minimize',
91-
},
92-
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3>\n<p> {title} </p>\n\t <!-- comment --> <img src="image.png" />'
93-
);
9487

95-
expect(result).toBe(
96-
`${GET_URL_CODE}module.exports = "<h3 customattr=\\"\\">#{number} {customer}</h3> <p> {title} </p> <img src=" + __url__(require("./image.png")) + " />";`
97-
);
98-
});
99-
// https://github.com/webpack/webpack/issues/752
100-
it('should not remove attributes by default', () => {
101-
const result = loader.call(
102-
{
103-
query: '?minimize',
104-
},
105-
'<input type="text" />'
106-
);
107-
108-
expect(result).toBe(
109-
`${GET_URL_CODE}module.exports = "<input type=text />";`
110-
);
111-
});
112-
it('should preserve comments', () => {
113-
const result = loader.call(
114-
{
115-
query: {
116-
minimize: {
117-
removeComments: false,
118-
},
119-
},
120-
},
121-
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src="image.png" />'
122-
);
123-
124-
expect(result).toBe(
125-
`${GET_URL_CODE}module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=" + __url__(require("./image.png")) + " />";`
126-
);
127-
});
12888
it('should preserve escaped quotes', () => {
12989
const result = loader.call(
13090
{},
@@ -136,58 +96,6 @@ describe('loader', () => {
13696
);
13797
});
13898

139-
it('should preserve comments and white spaces when minimizing (via webpack config property)', () => {
140-
const result = loader.call(
141-
{
142-
query: {
143-
minimize: {
144-
removeComments: false,
145-
collapseWhitespace: false,
146-
},
147-
},
148-
},
149-
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />'
150-
);
151-
152-
expect(result).toBe(
153-
`${GET_URL_CODE}module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=" + __url__(require("./image.png")) + " />";`
154-
);
155-
});
156-
157-
it('should preserve comments and white spaces when minizing (via webpack config property)', () => {
158-
const result = loader.call(
159-
{
160-
query: {
161-
minimize: {
162-
removeComments: false,
163-
collapseWhitespace: false,
164-
},
165-
},
166-
},
167-
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />'
168-
);
169-
170-
expect(result).toBe(
171-
`${GET_URL_CODE}module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=" + __url__(require("./image.png")) + " />";`
172-
);
173-
});
174-
175-
it('should treat attributes as case sensitive', () => {
176-
const result = loader.call(
177-
{
178-
query: {
179-
minimize: {
180-
caseSensitive: true,
181-
},
182-
},
183-
},
184-
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src="image.png" />'
185-
);
186-
187-
expect(result).toBe(
188-
`${GET_URL_CODE}module.exports = "<h3 customAttr=\\"\\">#{number} {customer}</h3><p>{title}</p><img src=" + __url__(require("./image.png")) + " />";`
189-
);
190-
});
19199
it('should not translate root-relative urls (without root query)', () => {
192100
const result = loader.call({}, 'Text <img src="/image.png">');
193101

test/minimize-option.test.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import loader from '../src';
2+
import { GET_URL_CODE } from '../src/constants';
3+
4+
describe('"minimize" option', () => {
5+
it('should be turned off by default', () => {
6+
const result = loader.call(
7+
{
8+
query: '',
9+
},
10+
'<!-- comment --><h1>My First Heading</h1>\n\n<p>My first paragraph.</p>'
11+
);
12+
13+
expect(result).toBe(
14+
`${GET_URL_CODE}module.exports = "<!-- comment --><h1>My First Heading</h1>\\n\\n<p>My first paragraph.</p>";`
15+
);
16+
});
17+
18+
it('should work with a value equal to "true"', () => {
19+
const result = loader.call(
20+
{
21+
query: {
22+
minimize: true,
23+
},
24+
},
25+
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3>\n<p> {title} </p>\n\t <!-- comment --> <img src="image.png" />'
26+
);
27+
28+
expect(result).toBe(
29+
`${GET_URL_CODE}module.exports = "<h3 customattr=\\"\\">#{number} {customer}</h3> <p> {title} </p> <img src=" + __url__(require("./image.png")) + " />";`
30+
);
31+
});
32+
33+
it('should not work with a value equal to "false"', () => {
34+
const result = loader.call(
35+
{
36+
query: {
37+
minimize: false,
38+
},
39+
},
40+
'<!-- comment --><h1>My First Heading</h1>\n\n<p>My first paragraph.</p>'
41+
);
42+
43+
expect(result).toBe(
44+
`${GET_URL_CODE}module.exports = "<!-- comment --><h1>My First Heading</h1>\\n\\n<p>My first paragraph.</p>";`
45+
);
46+
});
47+
48+
// https://github.com/webpack/webpack/issues/752
49+
it('should not remove attributes by default', () => {
50+
const result = loader.call(
51+
{
52+
query: '?minimize',
53+
},
54+
'<input type="text" />'
55+
);
56+
57+
expect(result).toBe(
58+
`${GET_URL_CODE}module.exports = "<input type=text />";`
59+
);
60+
});
61+
62+
it('should preserve comments', () => {
63+
const result = loader.call(
64+
{
65+
query: {
66+
minimize: {
67+
removeComments: false,
68+
},
69+
},
70+
},
71+
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src="image.png" />'
72+
);
73+
74+
expect(result).toBe(
75+
`${GET_URL_CODE}module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=" + __url__(require("./image.png")) + " />";`
76+
);
77+
});
78+
79+
it('should preserve comments and white spaces when minimizing', () => {
80+
const result = loader.call(
81+
{
82+
query: {
83+
minimize: {
84+
removeComments: false,
85+
collapseWhitespace: false,
86+
},
87+
},
88+
},
89+
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />'
90+
);
91+
92+
expect(result).toBe(
93+
`${GET_URL_CODE}module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=" + __url__(require("./image.png")) + " />";`
94+
);
95+
});
96+
97+
it('should treat attributes as case sensitive', () => {
98+
const result = loader.call(
99+
{
100+
query: {
101+
minimize: {
102+
caseSensitive: true,
103+
},
104+
},
105+
},
106+
'<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src="image.png" />'
107+
);
108+
109+
expect(result).toBe(
110+
`${GET_URL_CODE}module.exports = "<h3 customAttr=\\"\\">#{number} {customer}</h3><p>{title}</p><img src=" + __url__(require("./image.png")) + " />";`
111+
);
112+
});
113+
});
File renamed without changes.

0 commit comments

Comments
 (0)