1 | var parser = require('../');
|
2 | var test = require('tap').test;
|
3 | var fs = require('fs');
|
4 | var path = require('path');
|
5 |
|
6 | var files = {
|
7 | main: path.join(__dirname, '/ignore_missing/main.js'),
|
8 | other: path.join(__dirname, '/ignore_missing/other.js')
|
9 | };
|
10 |
|
11 | var sources = Object.keys(files).reduce(function (acc, file) {
|
12 | acc[file] = fs.readFileSync(files[file], 'utf8');
|
13 | return acc;
|
14 | }, {});
|
15 |
|
16 | test('ignoreMissing', function (t) {
|
17 | t.plan(1);
|
18 | var p = parser({ignoreMissing: true});
|
19 | p.end({file: files.main, entry: true});
|
20 |
|
21 | var rows = [];
|
22 | p.on('data', function (row) { rows.push(row) });
|
23 | p.on('end', function () {
|
24 | t.same(rows.sort(cmp), [
|
25 | {
|
26 | id: files.main,
|
27 | file: files.main,
|
28 | source: sources.main,
|
29 | entry: true,
|
30 | deps: { './other': files.other }
|
31 | },
|
32 | {
|
33 | id: files.other,
|
34 | file: files.other,
|
35 | source: sources.other,
|
36 | deps: { 'missingModule': undefined }
|
37 | }
|
38 | ].sort(cmp));
|
39 | });
|
40 | });
|
41 |
|
42 | test('ignoreMissing off', function (t) {
|
43 | t.plan(1);
|
44 | var p = parser();
|
45 | p.end({file: files.main, entry: true});
|
46 |
|
47 | var rows = [];
|
48 | p.on('data', function (row) { rows.push(row) });
|
49 | p.on('error', function (err) {
|
50 | t.match(
|
51 | String(err),
|
52 | /Cannot find module 'missingModule'/
|
53 | );
|
54 | });
|
55 | p.on('end', function () {
|
56 | t.fail('should have errored');
|
57 | });
|
58 | });
|
59 |
|
60 | function cmp (a, b) { return a.id < b.id ? -1 : 1 }
|