Path: blob/main/resolvers/webpack/test/packageMains.js
829 views
'use strict';12const chai = require('chai');3const expect = chai.expect;4const path = require('path');56const resolver = require('../');78const file = path.join(__dirname, 'package-mains', 'dummy.js');91011describe('packageMains', function () {1213it('captures module', function () {14expect(resolver.resolve('./module', file)).property('path')15.to.equal(path.join(__dirname, 'package-mains', 'module', 'src', 'index.js'));16});1718it('captures jsnext', function () {19expect(resolver.resolve('./jsnext', file)).property('path')20.to.equal(path.join(__dirname, 'package-mains', 'jsnext', 'src', 'index.js'));21});2223it('captures module instead of jsnext', function () {24expect(resolver.resolve('./module-and-jsnext', file)).property('path')25.to.equal(path.join(__dirname, 'package-mains', 'module-and-jsnext', 'src', 'index.js'));26});2728it('falls back from a missing "module" to "main"', function () {29expect(resolver.resolve('./module-broken', file)).property('path')30.to.equal(path.join(__dirname, 'package-mains', 'module-broken', 'main.js'));31});3233it('captures webpack', function () {34expect(resolver.resolve('./webpack', file)).property('path')35.to.equal(path.join(__dirname, 'package-mains', 'webpack', 'webpack.js'));36});3738it('captures jam (array path)', function () {39expect(resolver.resolve('./jam', file)).property('path')40.to.equal(path.join(__dirname, 'package-mains', 'jam', 'jam.js'));41});4243it('uses configured packageMains, if provided', function () {44expect(resolver.resolve('./webpack', file, { config: 'webpack.alt.config.js' })).property('path')45.to.equal(path.join(__dirname, 'package-mains', 'webpack', 'index.js'));46});4748it('always defers to module, regardless of config', function () {49expect(resolver.resolve('./module', file, { config: 'webpack.alt.config.js' })).property('path')50.to.equal(path.join(__dirname, 'package-mains', 'module', 'src', 'index.js'));51});5253it('always defers to jsnext:main, regardless of config', function () {54expect(resolver.resolve('./jsnext', file, { config: 'webpack.alt.config.js' })).property('path')55.to.equal(path.join(__dirname, 'package-mains', 'jsnext', 'src', 'index.js'));56});57});585960