meteor testing: error when trying to import - testing

I'm trying to test a meteor app like in the angular tutorial in meteor's website
https://www.meteor.com/tutorials/angular/testing
But when I add the import line
import { Meteor } from 'meteor/meteor';
and I run meteor test, I get this error:
W20160405-15:13:36.894(0)? (STDERR)
W20160405-15:13:36.894(0)? (STDERR) C:\Users\ys\AppData\Local\.meteor\packages\meteor-tool\1.3.1-rc.3\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
W20160405-15:13:36.895(0)? (STDERR) throw(ex);
W20160405-15:13:36.895(0)? (STDERR) ^
W20160405-15:13:36.895(0)? (STDERR) ReferenceError: require is not defined
W20160405-15:13:36.896(0)? (STDERR) at app\testing\add.test.js:5:21
W20160405-15:13:36.896(0)? (STDERR) at app\testing\add.test.js:21:4
W20160405-15:13:36.896(0)? (STDERR) at C:\Users\ys\AppData\Local\Temp\meteor-test-runxjisnu\.meteor\local\build\programs\server\boot.js:283:10
W20160405-15:13:36.896(0)? (STDERR) at Array.forEach (native)
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
W20160405-15:13:36.896(0)? (STDERR) at Function._.each._.forEach (C:\Users\ys\AppData\Local\.meteor\packages\meteor-tool\1.3.1-rc.3\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
W20160405-15:13:36.897(0)? (STDERR) at C:\Users\ys\AppData\Local\Temp\meteor-test-runxjisnu\.meteor\local\build\programs\server\boot.js:133:5
When I remove the import line, the test runs as it should, but without importing "chai" (or similar module) , I don't know how to get the assert function to work.

Related

UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Promise was collected

Once all tests finish successfully this exception occurs on the Circle CI:
W20200612-14:11:02.429(0)? (STDERR) (node:642) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Promise was collected
W20200612-14:11:02.429(0)? (STDERR) at Promise (/home/jenkins/humly-home/packages/hrm/node_modules/puppeteer/lib/Connection.js:183:56)
W20200612-14:11:02.429(0)? (STDERR) at new Promise (<anonymous>)
W20200612-14:11:02.429(0)? (STDERR) at CDPSession.send (/home/jenkins/humly-home/packages/hrm/node_modules/puppeteer/lib/Connection.js:182:12)
W20200612-14:11:02.429(0)? (STDERR) at ExecutionContext._evaluateInternal (/home/jenkins/humly-home/packages/hrm/node_modules/puppeteer/lib/ExecutionContext.js:107:44)
W20200612-14:11:02.429(0)? (STDERR) at ExecutionContext.evaluateHandle (/home/jenkins/humly-home/packages/hrm/node_modules/puppeteer/lib/ExecutionContext.js:57:17)
W20200612-14:11:02.430(0)? (STDERR) at ExecutionContext.<anonymous> (/home/jenkins/humly-home/packages/hrm/node_modules/puppeteer/lib/helper.js:112:23)
W20200612-14:11:02.430(0)? (STDERR) at WaitTask.rerun (/home/jenkins/humly-home/packages/hrm/node_modules/puppeteer/lib/DOMWorld.js:570:65)
W20200612-14:11:02.430(0)? (STDERR) at <anonymous>
W20200612-14:11:02.430(0)? (STDERR) at process._tickDomainCallback (internal/process/next_tick.js:229:7)
W20200612-14:11:02.430(0)? (STDERR) => awaited here:
W20200612-14:11:02.430(0)? (STDERR) at Function.Promise.await (/home/jenkins/.meteor/packages/promise/.0.11.2.1bomg6e.mbyx++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/promise_server.js:56:12)
W20200612-14:11:02.430(0)? (STDERR) at Promise.asyncApply (packages/meteortesting:browser-tests/browser/puppeteer.js:64:5)
W20200612-14:11:02.430(0)? (STDERR) at /home/jenkins/.meteor/packages/promise/.0.11.2.1bomg6e.mbyx++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40
W20200612-14:11:02.430(0)? (STDERR) (node:642) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)
W20200612-14:11:02.431(0)? (STDERR) (node:642) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Too long with no output (exceeded 1m0s): context deadline exceeded
After the investigation, I have found out that this is caused by unit tests using enzyme' shallow rendering. Once I remove these tests everything is fine, but I can't find anything wrong in them.
Also, this exception occurs every once in a few runs (2 - 3). Here is the typical unit test that makes this issue happen:
import React from "react";
import { expect } from "chai";
import { shallow, configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
// import sinon from "sinon";
import ExampleView from "./ExampleView";
configure({ adapter: new Adapter() });
const defaultProps = {
name: "test name",
text: "test value",
};
describe(".../ExampleView", () => {
before(() => {
// methods stubs
});
after(() => {
// restores
});
it("rendering component", () => {
const props = {
...defaultProps,
};
const wrapper = shallow(<ExampleView {...props} />);
const specificElement = wrapper.find(".specific-class-name");
expect(specificElement.text()).to.be.equal(defaultProps.text);
});
});
I think this is something related with meteortesting:mocha package and puppeteer, or maybe in between them. Here is the script I use to run unit tests on CI:
#!/bin/bash -eu
cd "$(dirname "${BASH_SOURCE[0]}")"/..
export PORT="${PORT:-5000}"
export ROOT_URL="http://localhost:${PORT}"
export TEST_BROWSER_DRIVER=puppeteer
export MOCHA_TIMEOUT=6000
cd node_modules/puppeteer/.local-chromium/linux-*/chrome-linux/
sudo chown root:root chrome_sandbox
sudo chmod 4755 chrome_sandbox
sudo cp -p chrome_sandbox /usr/local/sbin/chrome-devel-sandbox
export CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox
cd ../../../../../
meteor test --once --driver-package meteortesting:mocha --port "${PORT}" "$#"
I have tried with "-- --exit" in last command trying to force mocha to exit after all tests get done, but it does not help. Here is the list of versions I have:
meteor 1.8.3
node 8.17.0
puppeteer 1.20.0
meteortesting:browser-tests#1.3.1
meteortesting:mocha#1.1.3
meteortesting:mocha-core#6.2.2
react 16.12.0
sinon 7.5.0
chai 4.2.0
enzyme 3.10.0

ReferenceError: ReadableStream is not defined while running jest tests

My web app reads local files using a custom ReadableStream (in-order that I won't need to have a max file size that the platform supports) and it works great, both for correctly formatted files and error files. My app is built using React-Redux-Saga.
I'm now attempting to add limited e2e tests to my code to test the state management. I'm testing that when sending redux actions the state updates correctly. I'm testing the saga's using the package redux-saga-tester.
While running the jest client tests that read local files using the ReadableStream I built, I got an error ReferenceError: ReadableStream is not defined. What I understood is that the jsdom environment that jest uses is missing the ReadableStream implementation. I than added the web-streams-polyfill package to polyfill the ReadableStream class.
Now the validate file test is passing as in the browser:
test('Select and validate log file', async () => {
const testFile = testFileBuilder.valid();
storeTester.dispatch(fileSelected(testFile));
await storeTester.waitFor(FILE_VALIDATED);
const state = storeTester.getState().file;
expect(state.fileValidated).toBeTruthy();
});
My problem is that when I run a second validation test with an invalid file the test passes but prints an error to the console.
The test:
test('Select an invalid file - JSON error', async () => {
const testFile = testFileBuilder.errorJSON();
storeTester.dispatch(fileSelected(testFile));
await storeTester.waitFor(FILE_ERROR);
const state = storeTester.getState().file;
expect(state.fileValidated).toBeFalsy();
expect(state.fileError).toBeTruthy();
});
The error that is printed after the test completes successfully:
e.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (/home/noams/dev/web/visual-log-viewer/client/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19)
at Request.client.on.err (/home/noams/dev/web/visual-log-viewer/client/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:676:20)
at Request.emit (events.js:194:15)
at Request.onRequestError (/home/noams/dev/web/visual-log-viewer/client/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:189:13)
at Socket.socketErrorListener (_http_client.js:392:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19) undefined
Any subsequent file validation tests fail.
I'd appreciate any advice of how to tackle this issue.

React Packager 0.44.0

First of all I am new to react native platform and I am developing an app but I am facing one issue when I run my application after changes made in classes.
I am posting my logs below, Thank you for your help folks....
index.android.js (loads successfully but app do not run)
SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
{
Error: write EPIPE
at _errnoException (util.js:1022:11)
at Socket._writeGeneric (net.js:767:25)
at Socket._write (net.js:786:8)
at doWrite (_stream_writable.js:387:12)
at writeOrBuffer (_stream_writable.js:373:5)
at Socket.Writable.write (_stream_writable.js:290:11)
at Socket.write (net.js:704:40)
at Socket.Writable.end (_stream_writable.js:553:10)
at Socket.end (net.js:496:31)
at Promise.resolve.then.then.then.catch.then.message
(E:\FinalDownload\takeawaymobileapp\node_modules\react-native\packager\src\Server\symbolicate\worker.js
:35:33) code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }

Detox Error: Timeout of 120000ms exceeded. For async tests and hooks

I'm trying to run some e2e tests in my react-native up I'm using Detox but I keep getting the following error
1) "before all" hook:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
child_process.js:644
throw err;
^
Error: Command failed: node_modules/.bin/mocha e2e --opts e2e/mocha.opts
at checkExecSyncError (child_process.js:601:13)
at Object.execSync (child_process.js:641:13)
at runMocha (/Users/Almog/Full-Time-Employment/Construction-Cloud/RnD/CCMobileApp/node_modules/detox/local-cli/detox-test.js:72:6)
at Object.<anonymous> (/Users/Almog/Full-Time-Employment/Construction-Cloud/RnD/CCMobileApp/node_modules/detox/local-cli/detox-test.js:50:5)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
Try to run it with detox test --loglevel verbose flag it may provide you additional information on what is the issue.

How to mock propType of Image (React native) in Jest

I have the following error on a jest test that uses react-native and react-native-router-flux
Runtime Error
- TypeError: Cannot read property 'source' of undefined
at Object.<anonymous> (node_modules/react-native-router-flux/src/NavBar.js:155:45)
at Object.<anonymous> (node_modules/react-native-router-flux/src/DefaultRenderer.js:21:13)
at Object.<anonymous> (node_modules/react-native-router-flux/index.js:3:22)
This is the line that causes the trouble
backButtonImage: Image.propTypes.source,
so I guess that Image.propTypes is not defined correct
How can I fix this?