Skip to content

Commit

Permalink
Test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 9, 2023
1 parent 332c606 commit bf74ff0
Showing 1 changed file with 65 additions and 57 deletions.
122 changes: 65 additions & 57 deletions test/test.js
Expand Up @@ -7,21 +7,47 @@ const path = require('path');
const resolvePath = require('../index.js');

describe('resolve-dependency-path', () => {
it('throws if the dependency path is missing', () => {
assert.throws(() => {
resolvePath();
}, /^Error: dependency path not given$/);
});

it('throws if the filename is missing', () => {
assert.throws(() => {
resolvePath({
dependency: './bar'
});
}, /^Error: filename not given$/);
});

it('throws if the directory is missing', () => {
assert.throws(() => {
resolvePath({
dependency: './bar',
filename: path.join(__dirname, '/foo.js')
});
}, /^Error: directory not given$/);
});

it('resolves with absolute paths', () => {
const dependency = './bar';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: './bar',
filename: path.join(__dirname, '/foo.js'),
directory: __dirname
dependency,
filename,
directory
});
assert.ok(resolved.startsWith(__dirname));
});

it('resolves w/initial period, w/ending in .js', () => {
const depPath = './index';
const dependency = './index';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -30,11 +56,11 @@ describe('resolve-dependency-path', () => {
});

it('resolves w/initial period, w/o ending in .js', () => {
const depPath = './index.js';
const dependency = './index.js';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -43,11 +69,11 @@ describe('resolve-dependency-path', () => {
});

it('resolves w/o initial period, w/o ending in .js', () => {
const depPath = 'index';
const dependency = 'index';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -56,11 +82,11 @@ describe('resolve-dependency-path', () => {
});

it('resolves w/o initial period, w/ending in .js', () => {
const depPath = 'index.js';
const dependency = 'index.js';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -69,56 +95,38 @@ describe('resolve-dependency-path', () => {
});

it('resolves relative paths', () => {
const dependency = './bar.js';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: './bar',
filename: path.join(__dirname, '/foo.js'),
directory: __dirname
dependency,
filename,
directory
});
const expected = path.join(__dirname, '/bar.js');
assert.equal(resolved, expected);
});

it('resolves non-relative paths', () => {
const dependency = 'feature2/bar';
const filename = path.join(__dirname, '/feature1/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: 'feature2/bar',
dependency,
filename,
directory: __dirname
directory
});
const expected = path.join(__dirname, '/feature2/bar.js');
assert.equal(resolved, expected);
});

it('throws if the dependency path is missing', () => {
assert.throws(() => {
resolvePath();
});
});

it('throws if the filename is missing', () => {
assert.throws(() => {
resolvePath({
dependency: './bar'
});
});
});

it('throws if the directory is missing', () => {
assert.throws(() => {
resolvePath({
dependency: './bar',
filename: path.join(__dirname, '/foo.js')
});
});
});

describe('multiple period filenames', () => {
it('resolves with multiple periods in the dependency path', () => {
const depPath = './bar.baz.qux';
const dependency = './bar.baz.qux';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -127,11 +135,11 @@ describe('resolve-dependency-path', () => {
});

it('does not duplicate extensions', () => {
const depPath = '../index.js';
const dependency = '../index.js';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -141,23 +149,23 @@ describe('resolve-dependency-path', () => {
});

it('does not add the incorrect extension for sass files', () => {
const depPath = 'styles';
const dependency = 'styles';
const filename = path.join(__dirname, '/foo.scss');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
assert.equal(path.extname(resolved), '.scss');
});

it('does not add the incorrect extension for mustache files', () => {
const depPath = 'hgn!templates/foo.mustache';
const dependency = 'hgn!templates/foo.mustache';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -167,23 +175,23 @@ describe('resolve-dependency-path', () => {

describe('implicit jspm/systemjs style plugins', () => {
it('resolve w/initial period', () => {
const depPath = './templates/file.css!';
const dependency = './templates/file.css!';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
assert.equal(path.extname(resolved), '.css');
});

it('resolve w/o initial period', () => {
const depPath = 'templates/file.css!';
const dependency = 'templates/file.css!';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -193,23 +201,23 @@ describe('resolve-dependency-path', () => {

describe('explicit jspm/systemjs style plugins', () => {
it('resolve w/initial period', () => {
const depPath = './templates/file.txt!text';
const dependency = './templates/file.txt!text';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
assert.equal(path.extname(resolved), '.txt');
});

it('resolve w/o initial period', () => {
const depPath = 'templates/file.txt!text';
const dependency = 'templates/file.txt!text';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand All @@ -219,11 +227,11 @@ describe('resolve-dependency-path', () => {

describe('webpack support', () => {
it.skip('resolves properly', () => {
const depPath = './styles/foo.css';
const dependency = './styles/foo.css';
const filename = path.join(__dirname, '/foo.js');
const directory = __dirname;
const resolved = resolvePath({
dependency: depPath,
dependency,
filename,
directory
});
Expand Down

0 comments on commit bf74ff0

Please sign in to comment.