Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

jest-webpack-alias

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-webpack-alias - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

10

lib/preprocessor.js

@@ -37,3 +37,3 @@ var _ = require('lodash');

.map(function(dir) {
return unwin(path.resolve(webpackDir, dir));
return path.resolve(webpackDir, dir);
})

@@ -45,3 +45,3 @@ .filter(function(dir) {

nodeModulesDirs = moduleDirs.filter(function(dir) {
return path.basename(dir) == 'node_modules';
return path.basename(dir) === 'node_modules';
});

@@ -56,3 +56,3 @@ }

var absMatch = afterFirstDir ? path.join(matchingFirstDir, afterFirstDir) : matchingFirstDir;
var dirname = unwin(path.dirname(absMatch));
var dirname = path.dirname(absMatch);
var ext = find(fileExtensions, function(ext) {

@@ -94,3 +94,3 @@ return dirHas(dirname, path.basename(absMatch + ext));

var relPath = unwin(path.relative(srcDir, absMatch));
if (relPath.slice(0,1) != '.') {
if (relPath.slice(0, 1) != '.') {
relPath = './' + relPath;

@@ -102,3 +102,3 @@ }

function resolve(dependency, filename) {
if (dependency.slice(0, 1) == '.') {
if (dependency.slice(0, 1) === '.') {
return resolveRelativeDependency(dependency, filename);

@@ -105,0 +105,0 @@ }

{
"name": "jest-webpack-alias",
"version": "1.0.1",
"version": "1.0.2",
"description": "Preprocessor for Jest that is able to resolve require() statements using webpack aliases.",

@@ -5,0 +5,0 @@ "main": "lib/preprocessor.js",

@@ -66,2 +66,3 @@ # jest-webpack-alias

- Rewriting paths in `jest.dontMock()` lines
- `resolve.alias` (ironically, given package name)

@@ -68,0 +69,0 @@

@@ -50,2 +50,3 @@ var rewire = require('rewire');

readdirSync: sinon.spy(function(inPath) {
inPath = unwin(inPath);
var dirList = readdir[inPath];

@@ -101,3 +102,3 @@ if (!dirList) {

existsSync: sinon.spy(function(inPath) {
return !!readdir[inPath];
return !!readdir[unwin(inPath)];
})

@@ -104,0 +105,0 @@ };

@@ -7,2 +7,3 @@ var expect = require('./lib/expect');

var sinon = require('sinon');
var unwin = require('unwin');

@@ -21,2 +22,19 @@ describe('jest-webpack-alias module', function() {

function verifyDirHas(expected) {
expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(expected.length);
for (var i = 0; i < expected.length; i++) {
expect(unwin(dirHas.args[i][0])).to.eq(expected[i][0]);
expect(dirHas.args[i][1]).to.eq(expected[i][1]);
}
}
function verifyExistsSync(expected) {
expect(fs.existsSync).to.be.called;
expect(fs.existsSync.args).to.have.length(expected.length);
for (var i = 0; i < expected.length; i++) {
expect(unwin(fs.existsSync.args[i][0])).to.eq(expected[i][0]);
}
}
beforeEach(setup);

@@ -33,15 +51,10 @@

expect(fs.existsSync).to.be.called;
expect(fs.existsSync.args).to.have.length(4);
expect(fs.existsSync.args[0][0]).to.eq('/top/src');
expect(fs.existsSync.args[1][0]).to.eq('/top/bogus_dir');
expect(fs.existsSync.args[2][0]).to.eq('/top/node_modules');
expect(fs.existsSync.args[3][0]).to.eq('/top/web_modules');
expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(3);
expect(dirHas.args[0]).to.eql(['/top/src', 'dir1']);
expect(dirHas.args[1]).to.eql(['/top/src/dir1', 'lib1a']);
expect(dirHas.args[2]).to.eql(['/top/src/dir1', 'lib1a.js']);
verifyExistsSync([
['/top/src'], ['/top/bogus_dir'], ['/top/node_modules'], ['/top/web_modules']
]);
verifyDirHas([
['/top/src', 'dir1'],
['/top/src/dir1', 'lib1a'],
['/top/src/dir1', 'lib1a.js']
]);
expect(webpackInfo.read).to.be.calledOnce;

@@ -55,8 +68,8 @@ expect(output).to.eq("var lib1a = require('../src/dir1/lib1a.js');");

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(4);
expect(dirHas.args[0]).to.eql(['/top/src', 'dir1']);
expect(dirHas.args[1]).to.eql(['/top/src/dir1', 'lib1a.noext']);
expect(dirHas.args[2]).to.eql(['/top/src/dir1', 'lib1a.noext.js']);
expect(dirHas.args[3]).to.eql(['/top/src/dir1', 'lib1a.noext.jsx']);
verifyDirHas([
['/top/src', 'dir1'],
['/top/src/dir1', 'lib1a.noext'],
['/top/src/dir1', 'lib1a.noext.js'],
['/top/src/dir1', 'lib1a.noext.jsx']
]);
expect(output).to.eq("var lib1a = require('../src/dir1/lib1a.noext');");

@@ -75,7 +88,7 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(3);
expect(dirHas.args[0]).to.eql(['/top/src', 'dir1']);
expect(dirHas.args[1]).to.eql(['/top/src/dir1', 'lib1a']);
expect(dirHas.args[2]).to.eql(['/top/src/dir1', 'lib1a.js']);
verifyDirHas([
['/top/src', 'dir1'],
['/top/src/dir1', 'lib1a'],
['/top/src/dir1', 'lib1a.js']
]);
expect(output).to.eq("var lib1a = require('./lib1a.js');");

@@ -94,8 +107,8 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(4);
expect(dirHas.args[0]).to.eql(['/top/src', 'node1']);
expect(dirHas.args[1]).to.eql(['/top/src', 'node1.js']);
expect(dirHas.args[2]).to.eql(['/top/src', 'node1.jsx']);
expect(dirHas.args[3]).to.eql(['/top/node_modules', 'node1']);
verifyDirHas([
['/top/src', 'node1'],
['/top/src', 'node1.js'],
['/top/src', 'node1.jsx'],
['/top/node_modules', 'node1']
]);
expect(output).to.eq("var lib1a = require('node1');");

@@ -108,6 +121,6 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(2);
expect(dirHas.args[0]).to.eql(['/top/src', 'node1']);
expect(dirHas.args[1]).to.eql(['/top/node_modules', 'node1']);
verifyDirHas([
['/top/src', 'node1'],
['/top/node_modules', 'node1']
]);
expect(output).to.eq("var lib1a = require('node1/lib/submodule');");

@@ -126,13 +139,13 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(9);
expect(dirHas.args[0]).to.eql(['/top/src', 'web2']);
expect(dirHas.args[1]).to.eql(['/top/src', 'web2.js']);
expect(dirHas.args[2]).to.eql(['/top/src', 'web2.jsx']);
expect(dirHas.args[3]).to.eql(['/top/node_modules', 'web2']);
expect(dirHas.args[4]).to.eql(['/top/node_modules', 'web2.js']);
expect(dirHas.args[5]).to.eql(['/top/node_modules', 'web2.jsx']);
expect(dirHas.args[6]).to.eql(['/top/web_modules', 'web2']);
expect(dirHas.args[7]).to.eql(['/top/web_modules', 'web2.js']);
expect(dirHas.args[8]).to.eql(['/top/web_modules', 'web2.jsx']);
verifyDirHas([
['/top/src', 'web2'],
['/top/src', 'web2.js'],
['/top/src', 'web2.jsx'],
['/top/node_modules', 'web2'],
['/top/node_modules', 'web2.js'],
['/top/node_modules', 'web2.jsx'],
['/top/web_modules', 'web2'],
['/top/web_modules', 'web2.js'],
['/top/web_modules', 'web2.jsx']
]);
expect(output).to.eq("var lib1a = require('../web_modules/web2.jsx');");

@@ -151,13 +164,13 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(9);
expect(dirHas.args[0]).to.eql(['/top/src', 'bogus1']);
expect(dirHas.args[1]).to.eql(['/top/src', 'bogus1.js']);
expect(dirHas.args[2]).to.eql(['/top/src', 'bogus1.jsx']);
expect(dirHas.args[3]).to.eql(['/top/node_modules', 'bogus1']);
expect(dirHas.args[4]).to.eql(['/top/node_modules', 'bogus1.js']);
expect(dirHas.args[5]).to.eql(['/top/node_modules', 'bogus1.jsx']);
expect(dirHas.args[6]).to.eql(['/top/web_modules', 'bogus1']);
expect(dirHas.args[7]).to.eql(['/top/web_modules', 'bogus1.js']);
expect(dirHas.args[8]).to.eql(['/top/web_modules', 'bogus1.jsx']);
verifyDirHas([
['/top/src', 'bogus1'],
['/top/src', 'bogus1.js'],
['/top/src', 'bogus1.jsx'],
['/top/node_modules', 'bogus1'],
['/top/node_modules', 'bogus1.js'],
['/top/node_modules', 'bogus1.jsx'],
['/top/web_modules', 'bogus1'],
['/top/web_modules', 'bogus1.js'],
['/top/web_modules', 'bogus1.jsx']
]);
expect(output).to.eq("var lib1a = require('bogus1');");

@@ -176,6 +189,6 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(2);
expect(dirHas.args[0]).to.eql(['/top/src/dir1', 'lib1a']);
expect(dirHas.args[1]).to.eql(['/top/src/dir1', 'lib1a.js']);
verifyDirHas([
['/top/src/dir1', 'lib1a'],
['/top/src/dir1', 'lib1a.js']
]);
expect(output).to.eq("var lib1a = require('./lib1a.js');");

@@ -189,6 +202,6 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(2);
expect(dirHas.args[0]).to.eql(['/top/src/dir1', 'lib1a']);
expect(dirHas.args[1]).to.eql(['/top/src/dir1', 'lib1a.js']);
verifyDirHas([
['/top/src/dir1', 'lib1a'],
['/top/src/dir1', 'lib1a.js']
]);
expect(output).to.eq("var lib1a = require('../lib1a.js');");

@@ -201,7 +214,7 @@ });

expect(dirHas).to.be.called;
expect(dirHas.args).to.have.length(3);
expect(dirHas.args[0]).to.eql(['/top/src/dir1', 'bogus']);
expect(dirHas.args[1]).to.eql(['/top/src/dir1', 'bogus.js']);
expect(dirHas.args[2]).to.eql(['/top/src/dir1', 'bogus.jsx']);
verifyDirHas([
['/top/src/dir1', 'bogus'],
['/top/src/dir1', 'bogus.js'],
['/top/src/dir1', 'bogus.jsx']
]);
expect(output).to.eq("var lib1a = require('./bogus');");

@@ -208,0 +221,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc