-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Client (on server) tests for example interface #204
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove commented code or can we uncommunt it?
774aed1
to
924bbc9
Compare
Subscription: api.example.on('resmon', (data) => {
console.log({ data });
}); |
…to client-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'll get back to you later on that.
- The best way to test remoteMethod is to modify it so that it returns the same arguments passed, and to check that the result matches the arguments on the client.
To test the webhook I'd modify it to return all its arguments and check on the client that everything was resolved correctly. - What would be your intention with the resmon test? You could add the resmon api to give reports on demand, but I'd prefer to see the test case before delving any deeper.
- To confirm results of the file upload we would need a predefined file fixture which we will upload to the server, and then we would access app's resources folder, read newly creted file and compare it to the original. Preferably small enough file that would fit into memory.
metatests.testAsync('file/upload', (test) => {
const readable = fs.createReadable('path_to_fixture');
const writable = client.createStream();
readable.pipe(writable);
// once readable is piped
await client.socketCall('fileupload', {stremId: writable.streamId});
const ficture = readSync(fixture);
const result = readSync('path_to_new_file');
test.strictSame(result, fixture);
});
- I'd use the existing api/chat PSEUDOCODE as follows:
metatests.testAsync('event subscription', (test) => {
const MESSAGE = 'YER MESSAGE HERE, LAD';
client.api.chat.on('message', msg => test.strictEquals(msg, MESSAGE));
});
test/client.js
Outdated
const metatests = require('metatests'); | ||
const { Metacom } = require('metacom/lib/client'); | ||
|
||
let token = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the runTests
argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, explain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redefine runTests
as
onst runTests = (client, token) => {
To get rid of global parameters.
test/client.js
Outdated
|
||
metatests.testAsync('example/exception', async (test) => { | ||
try { | ||
await client.socketCall('example')('exception')(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to catch an exception to check the message and custom data in custom exceptions and errors
I have tried a lot of approaches to make tests in test/client.js work (those attempts are partially commented out in the code), but it seems there are significant problems with metacom/lib/client.js
|
I took all updates and changed test/client.js accordingly. There are still some problems, old and new:
|
I'm not sure how to test Metacom class in Client.js in Metacom package, for now, I have chosen to test the application code alongside to Example server.
However, there are some problems: