Skip to content

Commit

Permalink
Move test fixtures to a fixtures subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 16, 2024
1 parent a5339a0 commit 40eb7b1
Show file tree
Hide file tree
Showing 116 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lint": "eslint bin/cli.js lib \"test/*.js\"",
"debug": "node bin/cli.js --debug bin lib",
"generate": "npm run generate:small && npm run generate:madge",
"generate:small": "bin/cli.js --image /tmp/simple.svg test/cjs/circular/a.js",
"generate:small": "bin/cli.js --image /tmp/simple.svg test/fixtures/cjs/circular/a.js",
"generate:madge": "bin/cli.js --image /tmp/madge.svg bin lib",
"test:output": "./test/output.sh",
"release": "npm test && release-it"
Expand Down
2 changes: 1 addition & 1 deletion test/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('AMD', () => {
const dir = __dirname + '/amd';
const dir = __dirname + '/fixtures/amd';

it('finds recursive dependencies', (done) => {
madge(dir + '/ok/a.js').then((res) => {
Expand Down
70 changes: 35 additions & 35 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ describe('API', () => {
});

it('returns a Promise', () => {
madge(__dirname + '/cjs/a.js').should.be.Promise(); // eslint-disable-line new-cap
madge(__dirname + '/fixtures/cjs/a.js').should.be.Promise(); // eslint-disable-line new-cap
});

it('throws error if file or directory does not exists', (done) => {
madge(__dirname + '/missing.js').catch((err) => {
madge(__dirname + '/fixtures/missing.js').catch((err) => {
err.message.should.match(/no such file or directory/);
done();
}).catch(done);
});

it('takes single file as path', (done) => {
madge(__dirname + '/cjs/a.js').then((res) => {
madge(__dirname + '/fixtures/cjs/a.js').then((res) => {
res.obj().should.eql({
'a.js': ['b.js', 'c.js'],
'b.js': ['c.js'],
Expand All @@ -38,7 +38,7 @@ describe('API', () => {
});

it('takes an array of files as path and combines the result', (done) => {
madge([__dirname + '/cjs/a.js', __dirname + '/cjs/normal/d.js']).then((res) => {
madge([__dirname + '/fixtures/cjs/a.js', __dirname + '/fixtures/cjs/normal/d.js']).then((res) => {
res.obj().should.eql({
'a.js': ['b.js', 'c.js'],
'b.js': ['c.js'],
Expand All @@ -50,7 +50,7 @@ describe('API', () => {
});

it('take a single directory as path and find files in it', (done) => {
madge(__dirname + '/cjs/normal').then((res) => {
madge(__dirname + '/fixtures/cjs/normal').then((res) => {
res.obj().should.eql({
'a.js': ['sub/b.js'],
'd.js': [],
Expand All @@ -62,7 +62,7 @@ describe('API', () => {
});

it('takes an array of directories as path and compute the basedir correctly', (done) => {
madge([__dirname + '/cjs/multibase/1', __dirname + '/cjs/multibase/2']).then((res) => {
madge([__dirname + '/fixtures/cjs/multibase/1', __dirname + '/fixtures/cjs/multibase/2']).then((res) => {
res.obj().should.eql({
'1/a.js': [],
'2/b.js': []
Expand All @@ -89,7 +89,7 @@ describe('API', () => {
});

it('can exclude modules using RegExp', (done) => {
madge(__dirname + '/cjs/a.js', {
madge(__dirname + '/fixtures/cjs/a.js', {
excludeRegExp: ['^b.js$']
}).then((res) => {
res.obj().should.eql({
Expand All @@ -102,9 +102,9 @@ describe('API', () => {

it('extracts dependencies but excludes .git', (done) => {
// eslint-disable-next-line no-sync
fs.renameSync(`${__dirname}/git/.git_tmp`, `${__dirname}/git/.git`);
fs.renameSync(`${__dirname}/fixtures/git/.git_tmp`, `${__dirname}/fixtures/git/.git`);

madge(__dirname + '/git/a.js', {}).then((res) => {
madge(__dirname + '/fixtures/git/a.js', {}).then((res) => {
res.obj().should.eql({
'a.js': ['b.js', 'c.js'],
'b.js': ['c.js'],
Expand All @@ -115,13 +115,13 @@ describe('API', () => {
done();
}).finally(() => {
// eslint-disable-next-line no-sync
fs.renameSync(`${__dirname}/git/.git`, `${__dirname}/git/.git_tmp`);
fs.renameSync(`${__dirname}/fixtures/git/.git`, `${__dirname}/fixtures/git/.git_tmp`);
});
});

describe('dependencyFilter', () => {
it('will stop traversing when returning false', (done) => {
madge(__dirname + '/cjs/a.js', {
madge(__dirname + '/fixtures/cjs/a.js', {
dependencyFilter: () => {
return false;
}
Expand All @@ -134,7 +134,7 @@ describe('API', () => {
});

it('will not stop traversing when not returning anything', (done) => {
madge(__dirname + '/cjs/a.js', {
madge(__dirname + '/fixtures/cjs/a.js', {
dependencyFilter: () => {}
}).then((res) => {
res.obj().should.eql({
Expand All @@ -149,24 +149,24 @@ describe('API', () => {
it('will pass arguments to the function', (done) => {
let counter = 0;

madge(__dirname + '/cjs/a.js', {
madge(__dirname + '/fixtures/cjs/a.js', {
dependencyFilter: (dependencyFilePath, traversedFilePath, baseDir) => {
if (counter === 0) {
dependencyFilePath.should.match(/test\/cjs\/b\.js$/);
traversedFilePath.should.match(/test\/cjs\/a\.js$/);
baseDir.should.match(/test\/cjs$/);
dependencyFilePath.should.match(/test\/fixtures\/cjs\/b\.js$/);
traversedFilePath.should.match(/test\/fixtures\/cjs\/a\.js$/);
baseDir.should.match(/test\/fixtures\/cjs$/);
}

if (counter === 1) {
dependencyFilePath.should.match(/test\/cjs\/c\.js$/);
traversedFilePath.should.match(/test\/cjs\/a\.js$/);
baseDir.should.match(/test\/cjs$/);
dependencyFilePath.should.match(/test\/fixtures\/cjs\/c\.js$/);
traversedFilePath.should.match(/test\/fixtures\/cjs\/a\.js$/);
baseDir.should.match(/test\/fixtures\/cjs$/);
}

if (counter === 2) {
dependencyFilePath.should.match(/test\/cjs\/c\.js$/);
traversedFilePath.should.match(/test\/cjs\/b\.js$/);
baseDir.should.match(/test\/cjs$/);
dependencyFilePath.should.match(/test\/fixtures\/cjs\/c\.js$/);
traversedFilePath.should.match(/test\/fixtures\/cjs\/b\.js$/);
baseDir.should.match(/test\/fixtures\/cjs$/);
}

counter++;
Expand All @@ -179,7 +179,7 @@ describe('API', () => {

describe('obj()', () => {
it('returns dependency object', (done) => {
madge(__dirname + '/cjs/a.js').then((res) => {
madge(__dirname + '/fixtures/cjs/a.js').then((res) => {
res.obj().should.eql({
'a.js': ['b.js', 'c.js'],
'b.js': ['c.js'],
Expand All @@ -192,7 +192,7 @@ describe('API', () => {

describe('circular()', () => {
it('returns list of circular dependencies', (done) => {
madge(__dirname + '/cjs/circular/a.js').then((res) => {
madge(__dirname + '/fixtures/cjs/circular/a.js').then((res) => {
res.circular().should.eql([
['a.js', 'd.js']
]);
Expand All @@ -203,7 +203,7 @@ describe('API', () => {

describe('circularGraph()', () => {
it('returns graph with only circular dependencies', (done) => {
madge(__dirname + '/cjs/circular/a.js').then((res) => {
madge(__dirname + '/fixtures/cjs/circular/a.js').then((res) => {
res.circularGraph().should.eql({
'a.js': ['d.js'],
'd.js': ['a.js']
Expand All @@ -215,7 +215,7 @@ describe('API', () => {

describe('warnings()', () => {
it('returns an array of skipped files', (done) => {
madge(__dirname + '/cjs/missing.js').then((res) => {
madge(__dirname + '/fixtures/cjs/missing.js').then((res) => {
res.obj().should.eql({
'missing.js': ['c.js'],
'c.js': []
Expand All @@ -230,7 +230,7 @@ describe('API', () => {

describe('dot()', () => {
it('returns a promise resolved with graphviz DOT output', async () => {
const res = await madge(__dirname + '/cjs/b.js');
const res = await madge(__dirname + '/fixtures/cjs/b.js');
const output = await res.dot();
output.should.match(/digraph G/);
output.should.match(/bgcolor="#111111"/);
Expand All @@ -242,7 +242,7 @@ describe('API', () => {

describe('depends()', () => {
it('returns modules that depends on another', (done) => {
madge(__dirname + '/cjs/a.js').then((res) => {
madge(__dirname + '/fixtures/cjs/a.js').then((res) => {
res.depends('c.js').should.eql(['a.js', 'b.js']);
done();
}).catch(done);
Expand All @@ -251,7 +251,7 @@ describe('API', () => {

describe('orphans()', () => {
it('returns modules that no one is depending on', (done) => {
madge(__dirname + '/cjs/normal').then((res) => {
madge(__dirname + '/fixtures/cjs/normal').then((res) => {
res.orphans().should.eql(['a.js']);
done();
}).catch(done);
Expand All @@ -260,7 +260,7 @@ describe('API', () => {

describe('leaves()', () => {
it('returns modules that have no dependencies', (done) => {
madge(__dirname + '/cjs/normal').then((res) => {
madge(__dirname + '/fixtures/cjs/normal').then((res) => {
res.leaves().should.eql(['d.js']);
done();
}).catch(done);
Expand All @@ -269,7 +269,7 @@ describe('API', () => {

describe('svg()', () => {
it('returns a promise resolved with XML SVG output in a Buffer', (done) => {
madge(__dirname + '/cjs/b.js')
madge(__dirname + '/fixtures/cjs/b.js')
.then((res) => res.svg())
.then((output) => {
output.should.instanceof(Buffer);
Expand All @@ -292,7 +292,7 @@ describe('API', () => {
});

it('rejects if a filename is not supplied', (done) => {
madge(__dirname + '/cjs/a.js')
madge(__dirname + '/fixtures/cjs/a.js')
.then((res) => res.image())
.catch((err) => {
err.message.should.eql('imagePath not provided');
Expand All @@ -301,7 +301,7 @@ describe('API', () => {
});

it('rejects on unsupported image format', (done) => {
madge(__dirname + '/cjs/a.js')
madge(__dirname + '/fixtures/cjs/a.js')
.then((res) => res.image('image.zyx'))
.catch((err) => {
err.message.should.match(/Format: "zyx" not recognized/);
Expand All @@ -310,7 +310,7 @@ describe('API', () => {
});

it('rejects if graphviz is not installed', (done) => {
madge(__dirname + '/cjs/a.js', {graphVizPath: '/invalid/path'})
madge(__dirname + '/fixtures/cjs/a.js', {graphVizPath: '/invalid/path'})
.then((res) => res.image('image.png'))
.catch((err) => {
err.message.should.eql('Graphviz could not be found. Ensure that "gvpr" is in your $PATH. Error: spawn /invalid/path/gvpr ENOENT');
Expand All @@ -319,7 +319,7 @@ describe('API', () => {
});

it('writes image to file', (done) => {
madge(__dirname + '/cjs/a.js')
madge(__dirname + '/fixtures/cjs/a.js')
.then((res) => res.image(imagePath))
.then((writtenImagePath) => {
writtenImagePath.should.eql(imagePath);
Expand Down
2 changes: 1 addition & 1 deletion test/cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('CommonJS', () => {
const dir = __dirname + '/cjs';
const dir = __dirname + '/fixtures/cjs';

it('finds recursive dependencies', (done) => {
madge(dir + '/normal/a.js').then((res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('ES6', () => {
const dir = __dirname + '/es6';
const dir = __dirname + '/fixtures/es6';

it('extracts dependencies', (done) => {
madge(dir + '/absolute.js').then((res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/es7.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('ES7', () => {
const dir = __dirname + '/es7';
const dir = __dirname + '/fixtures/es7';

it('extracts dependencies', (done) => {
madge(dir + '/async.js').then((res) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/es6/absolute/a.js → test/fixtures/es6/absolute/a.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {B} from 'test/es6/absolute/b';

import {B} from 'test/es6/absolute/b';

export const A = 'A';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('Flow', () => {
const dir = __dirname + '/flow';
const dir = __dirname + '/fixtures/flow';

it('extracts ES module ependencies', (done) => {
madge(dir + '/es/calc.js').then((res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const madge = require('../lib/api');
require('should');

describe('JSX', () => {
const dir = __dirname + '/jsx';
const dir = __dirname + '/fixtures/jsx';

it('finds import in JSX files', (done) => {
madge(dir + '/basic.jsx').then((res) => {
Expand Down
12 changes: 6 additions & 6 deletions test/output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ desc "DEPENDS"
./bin/cli.js lib/api.js -d log.js

desc "CIRCULAR (OK)"
./bin/cli.js test/cjs/a.js -c
./bin/cli.js test/fixtures/cjs/a.js -c

desc "CIRCULAR (FOUND, NO INDEX COUNTING)"
./bin/cli.js test/cjs/circular/a.js -c --no-count
./bin/cli.js test/fixtures/cjs/circular/a.js -c --no-count

desc "CIRCULAR (FOUND, WITH INDEX COUNT)"
./bin/cli.js test/cjs/circular/a.js -c
./bin/cli.js test/fixtures/cjs/circular/a.js -c

desc "NPM"
./bin/cli.js test/cjs/npm.js --include-npm
./bin/cli.js test/fixtures/cjs/npm.js --include-npm

desc "STDIN"
./bin/cli.js --json lib/api.js | tr '[a-z]' '[A-Z]' | ./bin/cli.js --stdin
Expand All @@ -44,10 +44,10 @@ desc "SHOW EXTENSION"
./bin/cli.js lib/api.js --show-extension

desc "WARNINGS (NOTE)"
./bin/cli.js test/cjs/missing.js -c
./bin/cli.js test/fixtures/cjs/missing.js -c

desc "WARNINGS (LIST)"
./bin/cli.js test/cjs/missing.js -c --warning
./bin/cli.js test/fixtures/cjs/missing.js -c --warning

desc "ERROR"
./bin/cli.js file/not/found.js
Expand Down
2 changes: 1 addition & 1 deletion test/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ts = require('typescript');
require('should');

describe('TypeScript', () => {
const dir = __dirname + '/typescript';
const dir = __dirname + '/fixtures/typescript';

it('extracts module dependencies', (done) => {
madge(dir + '/import.ts').then((res) => {
Expand Down

0 comments on commit 40eb7b1

Please sign in to comment.