Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

several test cases after one adapter start #373

Closed
foxthefox opened this issue Jan 3, 2021 · 4 comments
Closed

several test cases after one adapter start #373

foxthefox opened this issue Jan 3, 2021 · 4 comments

Comments

@foxthefox
Copy link

foxthefox commented Jan 3, 2021

as of today it seems that the test cases with it() need to execute the harness.AdaperStartAndWait.
Having a real integration with a mock server, the whole startup of the adapter is processed with each it().
In my opinion it would be more helpful to have additional the approach to have the harness.AdaperStartAndWait in the before() and therefore only one adapter start is necessary.

have a look to https://github.com/foxthefox/ioBroker.fritzdect/tree/2.0.0-class
here I start the mock server in before() and in each it() it is necessary to manipulate the adapter settings and start the adapter, before the test cases are processed. Each device has its own it() for checking its correct creation. This is ca. 20 lines in log accompanied by 3000 lines of log for adapter start (per it()).
The log is truncated at approx.13000 lines, so the whole test can not be checked within the web window (only raw).
It works in such a way, but I think it could work like in the testAdapter.js way.

Here the simplified structure as of today:

tests.integration(path.join(__dirname, '..'), {
	defineAdditionalTests(getHarness) {
		describe('Test creation of devices', () => {
			before('start the emulation', () => {
				//start mock
			});
			it('device check 1', () => {
				return new Promise(async (resolve) => {
					const harness = getHarness();
					harness._objects.getObject('system.adapter.fritzdect.0', async (err, obj) => {
						obj.native.fritz_ip = 'http://localhost:3333';
						await harness._objects.setObjectAsync(obj._id, obj);
						// Start the adapter and wait until it has started
						await harness.startAdapterAndWait();
						harness.states.getState('fritzdect.0.DECT_087610006161.productname', function(err, state) {
							if (err) console.error(err);
							expect(state).to.exist;
							if (!state) {
								console.error('state "fritzdect.0.DECT_087610006161.productname" not set');
							} else {
								console.log('fritzdect.0.DECT_087610006161.productname      ... ' + state.val);
							}
							expect(state.val).to.exist;
							expect(state.val).to.be.equal('FRITZ!DECT 200');
						});
						// and many more states

					});
				});
			});
			it('device check 2', () => {
				return new Promise(async (resolve) => {
					const harness = getHarness();
					harness._objects.getObject('system.adapter.fritzdect.0', async (err, obj) => {
						obj.native.fritz_ip = 'http://localhost:3333';
						await harness._objects.setObjectAsync(obj._id, obj);
						// Start the adapter and wait until it has started
						await harness.startAdapterAndWait();
						harness.states.getState('fritzdect.0.DECT_087610006161.productname', function(err, state) {
							if (err) console.error(err);
							expect(state).to.exist;
							if (!state) {
								console.error('state "fritzdect.0.DECT_087610006161.productname" not set');
							} else {
								console.log('fritzdect.0.DECT_087610006161.productname      ... ' + state.val);
							}
							expect(state.val).to.exist;
							expect(state.val).to.be.equal('FRITZ!DECT 200');
						});
						// and many more states

					});
				});
			});
			// next it()
		});
	};
});

my idea:

tests.integration(path.join(__dirname, '..'), {
	defineAdditionalTests(getHarness) {
		describe('Test creation of devices', () => {
			before('start the emulation', () => {
				//start mock
				//setup harness
				const harness = getHarness();
				harness._objects.getObject('system.adapter.fritzdect.0', async (err, obj) => {
					obj.native.fritz_ip = 'http://localhost:3333';
					await harness._objects.setObjectAsync(obj._id, obj);
				});
				// Start the adapter and wait until it has started
				await harness.startAdapterAndWait();
			});
			it('device check 1', () => {
				return new Promise(async (resolve) => {
					harness.states.getState('fritzdect.0.DECT_087610006161.productname', function(err, state) {
						//tests
					});
					// and many more states
					});
				});
			});
			it('device check 2', () => {
				return new Promise(async (resolve) => {
					return new Promise(async (resolve) => {
						harness.states.getState('fritzdect.0.DECT_087610006161.productname', function(err, state) {
							//tests
						});
						// and many more states
						});
					});
				});
			// next it()
		});
	};
});
@AlCalzone
Copy link
Collaborator

Do you have a commit I could check out to quickly test this myself?

@foxthefox
Copy link
Author

foxthefox commented Jan 3, 2021

in the meantime I merged it to the master branch
https://github.com/foxthefox/ioBroker.fritzdect/tree/master
all test cases to the devices are now part of the integration.js

the idea from above is only to show where I would see the implementation of adapterstartandwait and would see an improvement (but there is no branch or coding for this ).

@AlCalzone
Copy link
Collaborator

fixed in #498

@foxthefox
Copy link
Author

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants