UNPKG

1.38 kBJavaScriptView Raw
1var parser = require('../');
2var test = require('tap').test;
3var fs = require('fs');
4var path = require('path');
5
6var files = {
7 main: path.join(__dirname, '/ignore_missing/main.js'),
8 other: path.join(__dirname, '/ignore_missing/other.js')
9};
10
11var sources = Object.keys(files).reduce(function (acc, file) {
12 acc[file] = fs.readFileSync(files[file], 'utf8');
13 return acc;
14}, {});
15
16var cache = {};
17cache[files.main] = {
18 source: sources.main,
19 deps: { './other': files.other }
20};
21cache[files.other] = {
22 source: sources.other,
23 deps: { 'missingModule': undefined }
24};
25
26test('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
52function cmp (a, b) { return a.id < b.id ? -1 : 1 }