Path: blob/main/resolvers/webpack/test/alias.js
829 views
'use strict';12const chai = require('chai');3const expect = chai.expect;4const path = require('path');56const webpack = require('../index');78const file = path.join(__dirname, 'files', 'dummy.js');910describe('resolve.alias', function () {11let resolved;12before(function () { resolved = webpack.resolve('foo', file); });1314it('is found', function () { expect(resolved).to.have.property('found', true); });1516it('is correct', function () {17expect(resolved).to.have.property('path')18.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'));19});20});2122// todo: reimplement with resolver function / config23// describe.skip('webpack alias spec', function () {24// // from table: https://webpack.github.io/docs/configuration.html#resolve-alias25// function tableLine(alias, xyz, xyzFile) {26// describe(JSON.stringify(alias), function () {27// it('xyz: ' + xyz, function () {28// expect(resolveAlias('xyz', alias)).to.equal(xyz);29// });30// it('xyz/file: ' + (xyzFile.name || xyzFile), function () {31// if (xyzFile === Error) {32// expect(resolveAlias.bind(null, 'xyz/file', alias)).to.throw(xyzFile);33// } else {34// expect(resolveAlias('xyz/file', alias)).to.equal(xyzFile);35// }36// });37// });38// }3940// tableLine( {}41// , 'xyz', 'xyz/file' );4243// tableLine( { xyz: '/absolute/path/to/file.js' }44// , '/absolute/path/to/file.js', 'xyz/file' );4546// tableLine( { xyz$: '/absolute/path/to/file.js' }47// , '/absolute/path/to/file.js', Error );4849// tableLine( { xyz: './dir/file.js' }50// , './dir/file.js', 'xyz/file' );5152// tableLine( { xyz$: './dir/file.js' }53// , './dir/file.js', Error );5455// tableLine( { xyz: '/some/dir' }56// , '/some/dir', '/some/dir/file' );5758// tableLine( { xyz$: '/some/dir' }59// , '/some/dir', 'xyz/file' );6061// tableLine( { xyz: './dir' }62// , './dir', './dir/file' );6364// tableLine( { xyz: 'modu' }65// , 'modu', 'modu/file' );6667// tableLine( { xyz$: 'modu' }68// , 'modu', 'xyz/file' );6970// tableLine( { xyz: 'modu/some/file.js' }71// , 'modu/some/file.js', Error );7273// tableLine( { xyz: 'modu/dir' }74// , 'modu/dir', 'modu/dir/file' );7576// tableLine( { xyz: 'xyz/dir' }77// , 'xyz/dir', 'xyz/dir/file' );7879// tableLine( { xyz$: 'xyz/dir' }80// , 'xyz/dir', 'xyz/file' );81// });8283// describe.skip('nested module names', function () {84// // from table: https://webpack.github.io/docs/configuration.html#resolve-alias85// function nestedName(alias, xyz, xyzFile) {86// describe(JSON.stringify(alias), function () {87// it('top/xyz: ' + xyz, function () {88// expect(resolveAlias('top/xyz', alias)).to.equal(xyz);89// });90// it('top/xyz/file: ' + (xyzFile.name || xyzFile), function () {91// if (xyzFile === Error) {92// expect(resolveAlias.bind(null, 'top/xyz/file', alias)).to.throw(xyzFile);93// } else {94// expect(resolveAlias('top/xyz/file', alias)).to.equal(xyzFile);95// }96// });97// });98// }99100// nestedName( { 'top/xyz': '/absolute/path/to/file.js' }101// , '/absolute/path/to/file.js', 'top/xyz/file' );102103// nestedName( { 'top/xyz$': '/absolute/path/to/file.js' }104// , '/absolute/path/to/file.js', Error );105106// nestedName( { 'top/xyz': './dir/file.js' }107// , './dir/file.js', 'top/xyz/file' );108109// nestedName( { 'top/xyz$': './dir/file.js' }110// , './dir/file.js', Error );111112// nestedName( { 'top/xyz': '/some/dir' }113// , '/some/dir', '/some/dir/file' );114115// nestedName( { 'top/xyz$': '/some/dir' }116// , '/some/dir', 'top/xyz/file' );117118// nestedName( { 'top/xyz': './dir' }119// , './dir', './dir/file' );120121// nestedName( { 'top/xyz': 'modu' }122// , 'modu', 'modu/file' );123124// nestedName( { 'top/xyz$': 'modu' }125// , 'modu', 'top/xyz/file' );126127// nestedName( { 'top/xyz': 'modu/some/file.js' }128// , 'modu/some/file.js', Error );129130// nestedName( { 'top/xyz': 'modu/dir' }131// , 'modu/dir', 'modu/dir/file' );132133// nestedName( { 'top/xyz': 'top/xyz/dir' }134// , 'top/xyz/dir', 'top/xyz/dir/file' );135136// nestedName( { 'top/xyz$': 'top/xyz/dir' }137// , 'top/xyz/dir', 'top/xyz/file' );138// });139140141