Path: blob/main/resolvers/node/test/paths.js
829 views
const expect = require('chai').expect;12const path = require('path');3const node = require('../index.js');45describe('paths', function () {6it('handles base path relative to CWD', function () {7expect(node.resolve('../', './test/file.js'))8.to.have.property('path')9.equal(path.resolve(__dirname, '../index.js'));10});11});121314describe('core', function () {15it('returns found, but null path, for core Node modules', function () {16const resolved = node.resolve('fs', './test/file.js');17expect(resolved).has.property('found', true);18expect(resolved).has.property('path', null);19});20});212223describe('default options', function () {2425it('finds .json files', function () {26expect(node.resolve('./data', './test/file.js'))27.to.have.property('path')28.equal(path.resolve(__dirname, './data.json'));29});3031it("ignores .json files if 'extensions' is redefined", function () {32expect(node.resolve('./data', './test/file.js', { extensions: ['.js'] }))33.to.have.property('found', false);34});3536it('finds mjs modules, with precedence over .js', function () {37expect(node.resolve('./native', './test/file.js'))38.to.have.property('path')39.equal(path.resolve(__dirname, './native.mjs'));40});4142it('finds .node modules, with lowest precedence', function () {43expect(node.resolve('./native.node', './test/file.js'))44.to.have.property('path')45.equal(path.resolve(__dirname, './native.node'));46});4748it('finds .node modules', function () {49expect(node.resolve('./dot-node', './test/file.js'))50.to.have.property('path')51.equal(path.resolve(__dirname, './dot-node.node'));52});5354it('still finds .js if explicit', function () {55expect(node.resolve('./native.js', './test/file.js'))56.to.have.property('path')57.equal(path.resolve(__dirname, './native.js'));58});59});606162