Skip to content

Commit

Permalink
test: more (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Dec 24, 2018
1 parent c17d9cd commit c5c7322
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/getCurrentRequest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const loaderUtils = require('../');

describe('getCurrentRequest()', () => {
it('when currentRequest is present', () => {
expect(
loaderUtils.getCurrentRequest({
currentRequest:
'/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css',
})
).toBe('/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css');
});

it('when currentRequest is present', () => {
expect(
loaderUtils.getCurrentRequest({
resource: 'foo.css',
loaders: [
{
loaderIndex: 0,
request: '/foo/bar/first-loader/index.js??ref--4-0',
},
{
loaderIndex: 1,
request: '/foo/bar/second-loader/index.js??ref--4-1',
},
],
})
).toBe(
'/foo/bar/first-loader/index.js??ref--4-0!/foo/bar/second-loader/index.js??ref--4-1!foo.css'
);
});
});
34 changes: 34 additions & 0 deletions test/getRemainingRequest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const loaderUtils = require('../');

describe('getRemainingRequest()', () => {
it('when currentRequest is present', () => {
expect(
loaderUtils.getRemainingRequest({
remainingRequest:
'/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css',
})
).toBe('/foo/bar/my-loader/index.js??ref--4-0!/foo/bar/url/url.css');
});

it('when currentRequest is present', () => {
expect(
loaderUtils.getRemainingRequest({
resource: 'foo.css',
loaders: [
{
loaderIndex: 0,
request: '/foo/bar/first-loader/index.js??ref--4-0',
},
{
loaderIndex: 1,
request: '/foo/bar/second-loader/index.js??ref--4-1',
},
],
})
).toBe(
'/foo/bar/first-loader/index.js??ref--4-0!/foo/bar/second-loader/index.js??ref--4-1!foo.css'
);
});
});
13 changes: 13 additions & 0 deletions test/interpolateName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,18 @@ describe('interpolateName()', () => {
'xyz-[name]-special',
'should provide a custom interpolateName function in options',
],
[
[
{
resourcePath: '/foo/xyz.png',
},
'[1]-[name].[ext]',
{
regExp: /\/([a-z0-9]+)\/[a-z0-9]+\.png$/,
},
],
'foo-xyz.png',
'should support regExp in options',
],
]);
});

0 comments on commit c5c7322

Please sign in to comment.