Path: blob/main/resolvers/webpack/test/externals.js
829 views
'use strict';12const chai = require('chai');3const expect = chai.expect;4const path = require('path');5const semver = require('semver');67const webpack = require('../index');89const file = path.join(__dirname, 'files', 'dummy.js');1011describe('externals', function () {12const settingsWebpack5 = {13config: require(path.join(__dirname, './files/webpack.config.webpack5.js')),14};1516it('works on just a string', function () {17const resolved = webpack.resolve('bootstrap', file);18expect(resolved).to.have.property('found', true);19expect(resolved).to.have.property('path', null);20});2122it('works on object-map', function () {23const resolved = webpack.resolve('jquery', file);24expect(resolved).to.have.property('found', true);25expect(resolved).to.have.property('path', null);26});2728it('works on a function', function () {29const resolved = webpack.resolve('underscore', file);30expect(resolved).to.have.property('found', true);31expect(resolved).to.have.property('path', null);32});3334it('returns null for core modules', function () {35const resolved = webpack.resolve('fs', file);36expect(resolved).to.have.property('found', true);37expect(resolved).to.have.property('path', null);38});3940it('works on a function (synchronous) for webpack 5', function () {41const resolved = webpack.resolve('underscore', file, settingsWebpack5);42expect(resolved).to.have.property('found', true);43expect(resolved).to.have.property('path', null);44});4546it('works on a function (synchronous) which uses getResolve for webpack 5', function () {47const resolved = webpack.resolve('graphql', file, settingsWebpack5);48expect(resolved).to.have.property('found', true);49expect(resolved).to.have.property('path', null);50});5152(semver.satisfies(process.version, '> 6') ? describe : describe.skip)('async function in webpack 5', function () {53const settingsWebpack5Async = () => ({54config: require(path.join(__dirname, './files/webpack.config.webpack5.async-externals.js')),55});5657it('prevents using an asynchronous function for webpack 5', function () {58const resolved = webpack.resolve('underscore', file, settingsWebpack5Async());59expect(resolved).to.have.property('found', false);60});6162it('prevents using a function which uses Promise returned by getResolve for webpack 5', function () {63const resolved = webpack.resolve('graphql', file, settingsWebpack5Async());64expect(resolved).to.have.property('found', false);65});66});67});686970