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 | var cache = {};
|
17 | cache[files.main] = {
|
18 | source: sources.main,
|
19 | deps: { './other': files.other }
|
20 | };
|
21 | cache[files.other] = {
|
22 | source: sources.other,
|
23 | deps: { 'missingModule': undefined }
|
24 | };
|
25 |
|
26 | test('ignoreMissing with cache', function (t) {
|
27 | t.plan(1);
|
28 | var p = parser({ cache: cache, ignoreMissing: true });
|
29 | p.end({file: files.main, entry: true});
|
30 |
|
31 | var rows = [];
|
32 | p.on('data', function (row) { rows.push(row) });
|
33 | p.on('end', function () {
|
34 | t.same(rows.sort(cmp), [
|
35 | {
|
36 | id: files.main,
|
37 | file: files.main,
|
38 | source: sources.main,
|
39 | entry: true,
|
40 | deps: { './other': files.other }
|
41 | },
|
42 | {
|
43 | id: files.other,
|
44 | file: files.other,
|
45 | source: sources.other,
|
46 | deps: { 'missingModule': undefined }
|
47 | }
|
48 | ].sort(cmp));
|
49 | });
|
50 | });
|
51 |
|
52 | function cmp (a, b) { return a.id < b.id ? -1 : 1 }
|