-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathexternals.js
68 lines (55 loc) · 2.48 KB
/
externals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
const chai = require('chai');
const expect = chai.expect;
const path = require('path');
const semver = require('semver');
const webpack = require('../index');
const file = path.join(__dirname, 'files', 'dummy.js');
describe('externals', function () {
const settingsWebpack5 = {
config: require(path.join(__dirname, './files/webpack.config.webpack5.js')),
};
it('works on just a string', function () {
const resolved = webpack.resolve('bootstrap', file);
expect(resolved).to.have.property('found', true);
expect(resolved).to.have.property('path', null);
});
it('works on object-map', function () {
const resolved = webpack.resolve('jquery', file);
expect(resolved).to.have.property('found', true);
expect(resolved).to.have.property('path', null);
});
it('works on a function', function () {
const resolved = webpack.resolve('underscore', file);
expect(resolved).to.have.property('found', true);
expect(resolved).to.have.property('path', null);
});
it('returns null for core modules', function () {
const resolved = webpack.resolve('fs', file);
expect(resolved).to.have.property('found', true);
expect(resolved).to.have.property('path', null);
});
it('works on a function (synchronous) for webpack 5', function () {
const resolved = webpack.resolve('underscore', file, settingsWebpack5);
expect(resolved).to.have.property('found', true);
expect(resolved).to.have.property('path', null);
});
it('works on a function (synchronous) which uses getResolve for webpack 5', function () {
const resolved = webpack.resolve('graphql', file, settingsWebpack5);
expect(resolved).to.have.property('found', true);
expect(resolved).to.have.property('path', null);
});
(semver.satisfies(process.version, '> 6') ? describe : describe.skip)('async function in webpack 5', function () {
const settingsWebpack5Async = () => ({
config: require(path.join(__dirname, './files/webpack.config.webpack5.async-externals.js')),
});
it('prevents using an asynchronous function for webpack 5', function () {
const resolved = webpack.resolve('underscore', file, settingsWebpack5Async());
expect(resolved).to.have.property('found', false);
});
it('prevents using a function which uses Promise returned by getResolve for webpack 5', function () {
const resolved = webpack.resolve('graphql', file, settingsWebpack5Async());
expect(resolved).to.have.property('found', false);
});
});
});