我的目标是在k6.js测试脚本中运行 socket.io-client 。
首先,我浏览了该库:
cd src/main/tests/
npm install browserify -S
browserify node_modules/socket.io-client/dist/socket.io.js --standalone io > socket-bundle.js
socket-bundle.js 文件已有效创建,并且可以在我的k6脚本中导入:
import io from './socket-bundle.js';
export default function() {
group("my socket test", () => {
var url = `https://my-endpoint.com/`;
const socket = io(url);
/* Also tried this:
var socket = io.connect(url, {
reconnect: true
});
*/
socket.on('connect', function () {
console.log("connected");
});
socket.on('event', function (data) {
console.log(data);
});
socket.on('disconnect', function () {
console.log("disconnect");
});
});
}
但是,当我运行它(在k6.js内部)时,我在core-js/shim.min.js
中遇到错误,这是库的依赖项:
TypeError: Value is not an object: undefined
at core-js/shim.min.js:9:19239(35)
at /src/main/tests/socket-bundle.js:9:25996(37)
at /src/main/tests/socket-bundle.js:9:26185(72)
at /src/main/tests/socket-bundle.js:9:26147(63)
at /src/main/tests/socket-bundle.js:9:26185(72)
at /src/main/tests/socket-bundle.js:9:26147(63)
at r (/src/main/tests/socket-bundle.js:9:24267(505))
at /src/main/tests/socket-bundle.js:9:18192(40)
at r (/src/main/tests/socket-bundle.js:9:16330(203))
at r (/src/main/tests/socket-bundle.js:9:753(110))
at /src/main/tests/query_trips.js:28:52(20)
at native
at test (/src/main/tests/query_trips.js:22:21(13))
at /src/main/tests/query_trips.js:50:44(4)
似乎浏览器没有正确包含依赖项。我应该以其他方式浏览库吗?