Skip to content

Commit c5c7322

Browse files
test: more (#132)
1 parent c17d9cd commit c5c7322

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

test/getCurrentRequest.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const loaderUtils = require('../');
4+
5+
describe('getCurrentRequest()', () => {
6+
it('when currentRequest is present', () => {
7+
expect(
8+
loaderUtils.getCurrentRequest({
9+
currentRequest:
10+
'/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css',
11+
})
12+
).toBe('/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css');
13+
});
14+
15+
it('when currentRequest is present', () => {
16+
expect(
17+
loaderUtils.getCurrentRequest({
18+
resource: 'foo.css',
19+
loaders: [
20+
{
21+
loaderIndex: 0,
22+
request: '/foo/bar/first-loader/index.js??ref--4-0',
23+
},
24+
{
25+
loaderIndex: 1,
26+
request: '/foo/bar/second-loader/index.js??ref--4-1',
27+
},
28+
],
29+
})
30+
).toBe(
31+
'/foo/bar/first-loader/index.js??ref--4-0!/foo/bar/second-loader/index.js??ref--4-1!foo.css'
32+
);
33+
});
34+
});

test/getRemainingRequest.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const loaderUtils = require('../');
4+
5+
describe('getRemainingRequest()', () => {
6+
it('when currentRequest is present', () => {
7+
expect(
8+
loaderUtils.getRemainingRequest({
9+
remainingRequest:
10+
'/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css',
11+
})
12+
).toBe('/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css');
13+
});
14+
15+
it('when currentRequest is present', () => {
16+
expect(
17+
loaderUtils.getRemainingRequest({
18+
resource: 'foo.css',
19+
loaders: [
20+
{
21+
loaderIndex: 0,
22+
request: '/foo/bar/first-loader/index.js??ref--4-0',
23+
},
24+
{
25+
loaderIndex: 1,
26+
request: '/foo/bar/second-loader/index.js??ref--4-1',
27+
},
28+
],
29+
})
30+
).toBe(
31+
'/foo/bar/first-loader/index.js??ref--4-0!/foo/bar/second-loader/index.js??ref--4-1!foo.css'
32+
);
33+
});
34+
});

test/interpolateName.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,18 @@ describe('interpolateName()', () => {
244244
'xyz-[name]-special',
245245
'should provide a custom interpolateName function in options',
246246
],
247+
[
248+
[
249+
{
250+
resourcePath: '/foo/xyz.png',
251+
},
252+
'[1]-[name].[ext]',
253+
{
254+
regExp: /\/([a-z0-9]+)\/[a-z0-9]+\.png$/,
255+
},
256+
],
257+
'foo-xyz.png',
258+
'should support regExp in options',
259+
],
247260
]);
248261
});

0 commit comments

Comments
 (0)