I've created reproduce repository.
Application code use assert
module of Node Core.
index.js
// application code use `assert` module const assert = require("assert"); export function hello(name) { assert(typeof name === "string"); return "Hello " + name; }
Test code:
const assert = require("power-assert"); import {hello} from "../src/index"; describe("hello", function () { it("should accept string", function () { hello(42); // Should throw error via assert and fail tests. }); });
These code are transformed by babel + babel-plugin-espower.
.babelrc
{ "presets": [ "es2015" ], "env": { "development": { "plugins": [ "babel-plugin-espower" ] } } }
When I do this:
ExpectedFail test
ActualPass test :(
ReasonApplication code is transformed to
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; var _powerAssertRecorder = function () { function PowerAssertRecorder() { this.captured = []; } PowerAssertRecorder.prototype._capt = function _capt(value, espath) { this.captured.push({ value: value, espath: espath }); return value; }; PowerAssertRecorder.prototype._expr = function _expr(value, source) { return { powerAssertContext: { value: value, events: this.captured }, source: source }; }; return PowerAssertRecorder; }(); exports.hello = hello; // application code use `assert` module var assert = require("assert"); function hello(name) { var _rec = new _powerAssertRecorder(); assert(_rec._expr(_rec._capt(_rec._capt(typeof name === "undefined" ? "undefined" : _typeof(name), "arguments/0/left") === "string", "arguments/0"), { content: "assert(typeof name === \"string\")", filepath: "src/index.js", line: 4 })); return "Hello " + name; } //# sourceMappingURL=index.js.map
_rec._expr
return object.
var assert = require("assert"); var object = _rec._expr(_rec._capt(_rec._capt(typeof name === "undefined" ? "undefined" : _typeof(name), "arguments/0/left") === "string", "arguments/0"), { content: "assert(typeof name === \"string\")", filepath: "src/index.js", line: 4 }); assert(object);
So, assert(Object)
never throw error. It causes this issue.
Do you have any solution?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4