1 // this is a weird meta test. It verifies that all the instances of
2 // `npm.config.get(...)` are:
3 // a) Simple strings, and not variables
5 // c) Defined in the `npmconf` package.
7 var test = require("tap").test
9 var path = require("path")
10 var root = path.resolve(__dirname, "..", "..")
11 var lib = path.resolve(root, "lib")
12 var nm = path.resolve(root, "node_modules")
13 var doc = path.resolve(root, "doc/misc/npm-config.md")
19 path.resolve(lib, "config.js"),
20 path.resolve(lib, "utils", "lifecycle.js")
23 test("get files", function (t) {
30 var files = fs.readdirSync(lib).map(function (f) {
31 return path.resolve(lib, f)
33 files.forEach(function (f) {
34 if (fs.statSync(f).isDirectory())
36 else if (f.match(/\.js$/))
42 test("get lines", function (t) {
43 FILES.forEach(function (f) {
45 var lines = fs.readFileSync(f, 'utf8').split('\n')
46 lines.forEach(function (l, i) {
47 var matches = l.split(/conf(?:ig)?\.get\(/g)
49 matches.forEach(function (m) {
50 m = m.split(')').shift()
51 var literal = m.match(/^['"].+['"]$/)
54 if (!m.match(/^\_/) && m !== 'argv')
59 } else if (exceptions.indexOf(f) === -1) {
60 t.fail("non-string-literal config used in " + f + ":" + i)
69 test("get docs", function (t) {
70 var d = fs.readFileSync(doc, "utf8").split("\n")
71 // walk down until the "## Config Settings" section
72 for (var i = 0; i < d.length && d[i] !== "## Config Settings"; i++);
74 // now gather up all the ^###\s lines until the next ^##\s
76 for (; i < d.length && !d[i].match(/^## /); i++) {
77 if (d[i].match(/^### /))
78 DOC[ d[i].replace(/^### /, '').trim() ] = true
80 t.pass("read the docs")
85 test("check configs", function (t) {
86 var defs = require("npmconf/config-defs.js")
87 var types = Object.keys(defs.types)
88 var defaults = Object.keys(defs.defaults)
90 for (var c in CONFS) {
91 if (CONFS[c].file.indexOf(lib) === 0) {
92 t.ok(DOC[c], "should be documented " + c + " "
93 + CONFS[c].file + ":" + CONFS[c].line)
94 t.ok(types.indexOf(c) !== -1, "should be defined in npmconf " + c)
95 t.ok(defaults.indexOf(c) !== -1, "should have default in npmconf " + c)
100 if (c !== "versions" && c !== "version") {
101 t.ok(CONFS[c], "config in doc should be used somewhere " + c)
102 t.ok(types.indexOf(c) !== -1, "should be defined in npmconf " + c)
103 t.ok(defaults.indexOf(c) !== -1, "should have default in npmconf " + c)
107 types.forEach(function(c) {
108 if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) {
109 t.ok(DOC[c], 'defined type should be documented ' + c)
110 t.ok(CONFS[c], 'defined type should be used ' + c)
114 defaults.forEach(function(c) {
115 if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) {
116 t.ok(DOC[c], 'defaulted type should be documented ' + c)
117 t.ok(CONFS[c], 'defaulted type should be used ' + c)