|
1 |
| -var tap = require("tap") |
2 |
| -var normalize = require("../lib/normalize") |
3 |
| -var fs = require("fs") |
4 |
| -var async = require("async") |
| 1 | +const t = require("tap") |
| 2 | +const normalize = require("../lib/normalize") |
| 3 | +const fs = require("fs") |
| 4 | +const { promisify } = require("util") |
| 5 | +const readFile = promisify(fs.readFile) |
5 | 6 |
|
6 |
| -var data |
7 |
| -var warn |
8 | 7 |
|
9 |
| -tap.test("consistent normalization", function(t) { |
10 |
| - var entries = [ |
| 8 | +t.test("consistent normalization", async t => { |
| 9 | + const entries = [ |
11 | 10 | 'read-package-json.json',
|
12 | 11 | 'http-server.json',
|
13 | 12 | "movefile.json",
|
14 | 13 | "node-module_exist.json"
|
15 | 14 | ]
|
16 |
| - var verifyConsistency = function(entryName, next) { |
17 |
| - warn = function(msg) { |
18 |
| - // t.equal("",msg) // uncomment to have some kind of logging of warnings |
| 15 | + const verifyConsistency = async (entryName) => { |
| 16 | + const warn = () => null |
| 17 | + const filename = __dirname + "/fixtures/" + entryName |
| 18 | + const contents = await readFile(filename) |
| 19 | + const data = JSON.parse(contents.toString()) |
| 20 | + normalize(data, warn) |
| 21 | + if(data.name == "node-module_exist") { |
| 22 | + t.same(data.bugs.url, "https://gist.github.com/3135914") |
19 | 23 | }
|
20 |
| - var filename = __dirname + "/fixtures/" + entryName |
21 |
| - fs.readFile(filename, function(err, contents) { |
22 |
| - if (err) return next(err) |
23 |
| - data = JSON.parse(contents.toString()) |
24 |
| - normalize(data, warn) |
25 |
| - if(data.name == "node-module_exist") { |
26 |
| - t.same(data.bugs.url, "https://gist.github.com/3135914") |
27 |
| - } |
28 |
| - if(data.name == "read-package-json") { |
29 |
| - t.same(data.bugs.url, "https://github.com/isaacs/read-package-json/issues") |
30 |
| - } |
31 |
| - if(data.name == "http-server") { |
32 |
| - t.same(data.bugs.url, "https://github.com/nodejitsu/http-server/issues") |
33 |
| - } |
34 |
| - if(data.name == "movefile") { |
35 |
| - t.same(data.bugs.url, "https://github.com/yazgazan/movefile/issues") |
36 |
| - } |
37 |
| - next(null) |
38 |
| - }) // fs.readFile |
39 |
| - } // verifyConsistency |
40 |
| - async.forEach(entries, verifyConsistency, function(err) { |
41 |
| - if (err) throw err |
42 |
| - t.end() |
43 |
| - }) |
44 |
| -}) // tap.test |
| 24 | + if(data.name == "read-package-json") { |
| 25 | + t.same(data.bugs.url, "https://github.com/isaacs/read-package-json/issues") |
| 26 | + } |
| 27 | + if(data.name == "http-server") { |
| 28 | + t.same(data.bugs.url, "https://github.com/nodejitsu/http-server/issues") |
| 29 | + } |
| 30 | + if(data.name == "movefile") { |
| 31 | + t.same(data.bugs.url, "https://github.com/yazgazan/movefile/issues") |
| 32 | + } |
| 33 | + } |
| 34 | + return Promise.all(entries.map(i => verifyConsistency(i))) |
| 35 | +}) |
0 commit comments