123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- var fs = require('fs');
- var path = require('path');
- var mdeps = require('../');
- var test = require('tap').test;
- var nodeResolve = require('resolve');
- var browserResolve = require('browser-resolve');
- var missing = path.join(__dirname, '/missing');
- var files = {
- foo: path.join(__dirname, '/files/resolve/foo/foo.js'),
- bar: path.join(__dirname, '/files/resolve/bar/bar.js'),
- bar2: path.join(__dirname, '/files/resolve/bar/bar2.js'),
- baz: path.join(__dirname, '/files/resolve/foo/baz/baz.js')
- };
- var sources = Object.keys(files)
- .reduce(function (acc, file) {
- acc[file] = fs.readFileSync(files[file], 'utf8');
- return acc;
- }, {});
- var expectedRows = [
- {
- "deps": {},
- "file": files.baz,
- "id": files.baz,
- "source": sources.baz
- },
- {
- "deps": {},
- "file": files.bar2,
- "id": files.bar2,
- "source": sources.bar2
- },
- {
- "deps": {
- "./bar2": files.bar2
- },
- "file": files.bar,
- "id": files.bar,
- "source": sources.bar
- },
- {
- "deps": {
- "../bar/bar.js": files.bar,
- "./baz/baz.js": files.baz
- },
- "entry": true,
- "file": files.foo,
- "id": "foo",
- "source": sources.foo
- }
- ];
- test('browser resolve - missing', function (t) {
- t.plan(1);
- var d = mdeps({resolve: browserResolve});
- d.end({id: 'missing', file: missing, entry: true});
- d.on('end', function () {
- t.fail('errored');
- });
- d.on('error', function (err) {
- t.match(
- String(err),
- /Cannot find module .*/
- );
- });
- });
- test('node resolve - missing', function (t) {
- t.plan(1);
- var d = mdeps({resolve: nodeResolve});
- d.end({id: 'missing', file: missing, entry: true});
- d.on('end', function () {
- t.fail('errored');
- });
- d.on('error', function (err) {
- t.match(
- String(err),
- /Cannot find module .*/
- );
- });
- });
- test('browser resolve', function (t) {
- t.plan(1);
- var d = mdeps({resolve: browserResolve});
- d.end({id: 'foo', file: files.foo, entry: true});
- var rows = [];
- d.on('data', function (row) {rows.push(row)});
- d.on('end', function () {
- t.same(rows, expectedRows);
- });
- d.on('error', function () {
- t.fail('errored');
- });
- });
- test('node resolve', function (t) {
- t.plan(1);
- var d = mdeps({resolve: nodeResolve});
- d.end({id: 'foo', file: files.foo, entry: true});
- var rows = [];
- d.on('data', function (row) {rows.push(row)});
- d.on('end', function () {
- t.same(rows, expectedRows);
- });
- d.on('error', function () {
- t.fail('errored');
- });
- });
|