Files: 938b7ea4cfaa3cef6e1690b9ef3ea8bd7a0d2de1 / test / test-50-should-disclose-package / main.js
1806 bytesRaw
1 | |
2 | |
3 | 'use strict'; |
4 | |
5 | const path = require('path'); |
6 | const assert = require('assert'); |
7 | const utils = require('../utils.js'); |
8 | |
9 | assert(!module.parent); |
10 | assert(__dirname === process.cwd()); |
11 | |
12 | const target = process.argv[2] || 'host'; |
13 | const input = './test-x-index.js'; |
14 | const output = './test-output.exe'; |
15 | const standard = 'stdout'; |
16 | |
17 | function rightReducer (mappy, line, index, right) { |
18 | if ((line.indexOf('Cannot resolve') >= 0) || |
19 | (line.indexOf('The file was included') >= 0)) { |
20 | const name = path.basename(right[index + 1]); |
21 | let value = right[index].split(' as ')[1] || ''; |
22 | value = value || right[index].split(' Warning ')[1]; |
23 | if (mappy[name]) assert.equal(mappy[name], value); |
24 | mappy[name] = value; |
25 | } |
26 | |
27 | return mappy; |
28 | } |
29 | |
30 | for (const pub of [ false, true ]) { |
31 | let right; |
32 | |
33 | const inspect = (standard === 'stdout') |
34 | ? [ 'inherit', 'pipe', 'inherit' ] |
35 | : [ 'inherit', 'inherit', 'pipe' ]; |
36 | |
37 | right = utils.pkg.sync([ |
38 | '--debug', |
39 | '--target', target, |
40 | '--output', output, input |
41 | ].concat(pub ? [ '--public' ] : []), inspect); |
42 | |
43 | assert(right.indexOf('\x1B\x5B') < 0, 'colors detected'); |
44 | |
45 | right = right.split('\n'); |
46 | const mappy = right.reduce(rightReducer, {}); |
47 | |
48 | const lines = Object.keys(mappy).sort().map(function (key) { |
49 | return key + ' = ' + mappy[key]; |
50 | }).join('\n') + '\n'; |
51 | |
52 | assert.equal(lines, |
53 | 'connect.js = DISCLOSED code (with sources)\n' + |
54 | 'has-no-license.js = bytecode (no sources)\n' + |
55 | 'has-permissive-license.js = DISCLOSED code (with sources)\n' + |
56 | 'has-strict-license.js = bytecode (no sources)\n' + |
57 | 'package.json = DISCLOSED code (with sources)\n' + |
58 | (pub ? 'test-x-index.js = DISCLOSED code (with sources)\n' : |
59 | 'test-x-index.js = bytecode (no sources)\n') |
60 | ); |
61 | |
62 | utils.vacuum.sync(output); |
63 | } |
64 |
Built with git-ssb-web