readme-assert 6.0.3 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +31 -40
- package/readme.md +90 -75
- package/src/cli.js +106 -0
- package/src/comment-to-assert.js +138 -0
- package/src/extract.js +66 -0
- package/src/generate.js +96 -0
- package/src/index.js +4 -0
- package/src/run.js +320 -0
- package/cli.js +0 -9
- package/lib/cli.js +0 -62
- package/lib/extract.js +0 -74
- package/lib/global-assert.js +0 -144
- package/lib/index.js +0 -111
- package/lib/runInThisContext.js +0 -45
- package/license +0 -21
package/lib/global-assert.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _assert = _interopRequireWildcard(require("assert"));
|
|
4
|
-
|
|
5
|
-
var _tapYaml = require("tap-yaml");
|
|
6
|
-
|
|
7
|
-
var _stackUtils = _interopRequireWildcard(require("stack-utils"));
|
|
8
|
-
|
|
9
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
|
10
|
-
|
|
11
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
12
|
-
|
|
13
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
14
|
-
|
|
15
|
-
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
|
16
|
-
|
|
17
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
18
|
-
|
|
19
|
-
console.log("TAP version 13");
|
|
20
|
-
var tests = 0;
|
|
21
|
-
var passes = 0;
|
|
22
|
-
var failures = 0;
|
|
23
|
-
var stackUtils = new _stackUtils["default"]({
|
|
24
|
-
internals: [].concat(_toConsumableArray((0, _stackUtils.nodeInternals)()), [/\/readme-assert\/lib\//])
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
function printObject(obj) {
|
|
28
|
-
console.log(" ---");
|
|
29
|
-
console.log((0, _tapYaml.stringify)(obj, 4).replace(/^/gm, " "));
|
|
30
|
-
console.log(" ...");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function test(message, fn) {
|
|
34
|
-
var _arguments = arguments;
|
|
35
|
-
return function () {
|
|
36
|
-
var args = Array.prototype.slice.call(_arguments);
|
|
37
|
-
tests++;
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
fn.apply(_assert["default"], [args]);
|
|
41
|
-
console.log("ok ".concat(tests, " ").concat(message || ""));
|
|
42
|
-
passes++;
|
|
43
|
-
} catch (err) {
|
|
44
|
-
console.log("not ok ".concat(tests, " ").concat(message || ""));
|
|
45
|
-
failures++;
|
|
46
|
-
|
|
47
|
-
if ("actual" in err && "expected" in err && "operator" in err) {
|
|
48
|
-
printObject({
|
|
49
|
-
operator: err.operator,
|
|
50
|
-
actual: err.actual,
|
|
51
|
-
expected: err.expected,
|
|
52
|
-
stack: stackUtils.clean(err.stack).split("\n").slice(1).join("\n")
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
printObject(err);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var assert = function assert(value, message) {
|
|
62
|
-
return test(message, function () {
|
|
63
|
-
return (0, _assert["default"])(value, message);
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
assert.deepEqual = function (actual, expected, message) {
|
|
68
|
-
test(message, function () {
|
|
69
|
-
return (0, _assert.deepEqual)(actual, expected, message);
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
assert.deepStrictEqual = function (actual, expected, message) {
|
|
74
|
-
test(message, function () {
|
|
75
|
-
return (0, _assert.deepStrictEqual)(actual, expected, message);
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
assert.doesNotThrow = function (block, error, message) {
|
|
80
|
-
test(message, function () {
|
|
81
|
-
return (0, _assert.doesNotThrow)(block, error, message);
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
assert.equal = function (actual, expected, message) {
|
|
86
|
-
test(message, function () {
|
|
87
|
-
return (0, _assert.equal)(actual, expected, message);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
assert.fail = function (actual, expected, message, operator) {
|
|
92
|
-
test(message, function () {
|
|
93
|
-
return (0, _assert.fail)(actual, expected, message, operator);
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
assert.ifError = function (value) {
|
|
98
|
-
test("", function () {
|
|
99
|
-
return (0, _assert.ifError)(value);
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
assert.notDeepEqual = function (actual, expected, message) {
|
|
104
|
-
test(message, function () {
|
|
105
|
-
return (0, _assert.notDeepEqual)(actual, expected, message);
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
assert.notDeepStrictEqual = function (actual, expected, message) {
|
|
110
|
-
test(message, function () {
|
|
111
|
-
return (0, _assert.notDeepStrictEqual)(actual, expected, message);
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
assert.ok = function (value, message) {
|
|
116
|
-
test(message, function () {
|
|
117
|
-
return (0, _assert.ok)(value, message);
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
assert["throws"] = function (block, error, message) {
|
|
122
|
-
test(message, function () {
|
|
123
|
-
return (0, _assert["throws"])(block, error, message);
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
process.on("uncaughtException", function (err) {
|
|
128
|
-
console.log("Bail out! Uncaught exception ".concat(err.name));
|
|
129
|
-
printObject(err);
|
|
130
|
-
process.exit(1);
|
|
131
|
-
});
|
|
132
|
-
process.on("exit", function (code) {
|
|
133
|
-
if (code === 0) {
|
|
134
|
-
console.log("1..".concat(tests));
|
|
135
|
-
console.log("# tests ".concat(tests));
|
|
136
|
-
console.log("# pass ".concat(passes));
|
|
137
|
-
console.log("# fail ".concat(failures));
|
|
138
|
-
|
|
139
|
-
if (failures > 0) {
|
|
140
|
-
process.reallyExit(1);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
global.assert = assert;
|
package/lib/index.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = run;
|
|
7
|
-
|
|
8
|
-
var babel = _interopRequireWildcard(require("@babel/core"));
|
|
9
|
-
|
|
10
|
-
var _pluginTransformTypescript = _interopRequireDefault(require("@babel/plugin-transform-typescript"));
|
|
11
|
-
|
|
12
|
-
var _presetEnv = _interopRequireDefault(require("@babel/preset-env"));
|
|
13
|
-
|
|
14
|
-
var _babelPluginTransformCommentToAssert = _interopRequireDefault(require("babel-plugin-transform-comment-to-assert"));
|
|
15
|
-
|
|
16
|
-
var _babelPluginTransformRenameImport = _interopRequireDefault(require("babel-plugin-transform-rename-import"));
|
|
17
|
-
|
|
18
|
-
var _sourceMapSupport = _interopRequireDefault(require("source-map-support"));
|
|
19
|
-
|
|
20
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
21
|
-
|
|
22
|
-
var _path = _interopRequireDefault(require("path"));
|
|
23
|
-
|
|
24
|
-
var _pkgUp = _interopRequireDefault(require("pkg-up"));
|
|
25
|
-
|
|
26
|
-
var _extract2 = _interopRequireDefault(require("./extract"));
|
|
27
|
-
|
|
28
|
-
var _runInThisContext = require("./runInThisContext");
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
-
|
|
32
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
|
33
|
-
|
|
34
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
35
|
-
|
|
36
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
37
|
-
|
|
38
|
-
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
|
39
|
-
|
|
40
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
41
|
-
|
|
42
|
-
function run(main, req, shouldPrintCode, babelrc, filePath, auto, all) {
|
|
43
|
-
var sourceMaps = !shouldPrintCode;
|
|
44
|
-
var sourceMapsFile = shouldPrintCode ? _path["default"].join(_path["default"].dirname(filePath), "readme.md.js") : filePath;
|
|
45
|
-
req.forEach(function (f) {
|
|
46
|
-
require(require.resolve(f, {
|
|
47
|
-
paths: [process.cwd()]
|
|
48
|
-
}));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
var mdDirname = _path["default"].dirname(filePath);
|
|
52
|
-
|
|
53
|
-
process.chdir(mdDirname);
|
|
54
|
-
var mdText = read(filePath);
|
|
55
|
-
|
|
56
|
-
var rootPkg = _pkgUp["default"].sync();
|
|
57
|
-
|
|
58
|
-
var pkg = JSON.parse(read(rootPkg));
|
|
59
|
-
|
|
60
|
-
var _extract = (0, _extract2["default"])(mdText, {
|
|
61
|
-
auto: auto,
|
|
62
|
-
all: all
|
|
63
|
-
}),
|
|
64
|
-
code = _extract.code,
|
|
65
|
-
hasTypescript = _extract.hasTypescript;
|
|
66
|
-
|
|
67
|
-
var transformed = babel.transform(code, {
|
|
68
|
-
babelrc: babelrc,
|
|
69
|
-
sourceMaps: sourceMaps,
|
|
70
|
-
plugins: [].concat(_toConsumableArray(hasTypescript ? [_pluginTransformTypescript["default"]] : []), [_babelPluginTransformCommentToAssert["default"], rootPkg ? [_babelPluginTransformRenameImport["default"], {
|
|
71
|
-
replacement: main || process.cwd(),
|
|
72
|
-
original: pkg.name
|
|
73
|
-
}] : undefined]),
|
|
74
|
-
presets: [_presetEnv["default"]],
|
|
75
|
-
filename: sourceMapsFile
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (sourceMaps) {
|
|
79
|
-
_sourceMapSupport["default"].install({
|
|
80
|
-
retrieveSourceMap: function retrieveSourceMap(request) {
|
|
81
|
-
if (request === filePath) {
|
|
82
|
-
return {
|
|
83
|
-
url: sourceMapsFile,
|
|
84
|
-
map: transformed.map
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (shouldPrintCode) {
|
|
94
|
-
printCode(transformed.code, sourceMapsFile);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
require("./global-assert");
|
|
98
|
-
|
|
99
|
-
(0, _runInThisContext.runInThisContext)(transformed.code, sourceMapsFile);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function read(file) {
|
|
103
|
-
return _fs["default"].readFileSync(_path["default"].join(file), "utf-8");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function printCode(code, sourceMapsFile) {
|
|
107
|
-
console.log("\n# ", sourceMapsFile);
|
|
108
|
-
code.split("\n").forEach(function (l, i) {
|
|
109
|
-
return console.log("# ".concat(String(i + 1).padEnd(3, " "), " ").concat(l));
|
|
110
|
-
});
|
|
111
|
-
}
|
package/lib/runInThisContext.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.runInThisContext = void 0;
|
|
7
|
-
|
|
8
|
-
var path = require("path");
|
|
9
|
-
|
|
10
|
-
var vm = require("vm");
|
|
11
|
-
|
|
12
|
-
var Module = require("module");
|
|
13
|
-
|
|
14
|
-
function createRequire(mod) {
|
|
15
|
-
var Mod = mod.constructor;
|
|
16
|
-
|
|
17
|
-
function require(path) {
|
|
18
|
-
return mod.require(path);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function resolve(request) {
|
|
22
|
-
return Mod._resolveFilename(request, mod);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
require.resolve = resolve;
|
|
26
|
-
require.main = process.mainModule;
|
|
27
|
-
require.extensions = Mod._extensions;
|
|
28
|
-
require.cache = Mod._cache;
|
|
29
|
-
return require;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var runInThisContext = function runInThisContext(code, filename) {
|
|
33
|
-
var script = new vm.Script(Module.wrap(code), {
|
|
34
|
-
filename: filename,
|
|
35
|
-
paths: path.dirname(filename),
|
|
36
|
-
breakOnSigint: true
|
|
37
|
-
}).runInThisContext();
|
|
38
|
-
var scriptModule = new Module(filename, module);
|
|
39
|
-
scriptModule.filename = filename;
|
|
40
|
-
scriptModule.paths = Module._nodeModulePaths(path.dirname(filename));
|
|
41
|
-
script.bind(scriptModule);
|
|
42
|
-
return script(scriptModule.exports, createRequire(scriptModule), scriptModule, filename, path.dirname(filename));
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
exports.runInThisContext = runInThisContext;
|
package/license
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016 Sigurd Fosseng
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|