Closed eddeee888 closed 5 years ago
@eddeee888 , thanks for the detailed info. In most cases, yes, your local and the remote CI should behave the same. However, in the current version the tests you run locally rely on your workspace configuration and not on Bit configuration. So, it's possible that the tests pass on your local but fail on the remote. You can also try importing your components on another directory and test them there, it'll fail with the same error you got from the remote. We are working on a solution to fix this by having the same procedure on the local and on the remote.
According to your specific error, it seemed to me that the await
wasn't used correctly. Eliminating entirely the async/await
, fixes the issue. Probably the function doesn't return a Promise.
Here is the fixed version of the tests:
import email from './emailValidation';
describe('emailValidation()', () => {
const valid = 'abc@gmail.com';
const invalidWrongFormat = 'asdsadasd';
it('emailValidation - valid', () => {
expect(email.validate(valid)).resolves.not.toThrow();
expect(email.validate(valid)).resolves.toBe(valid);
});
it('emailValidation - invalid: wrong email format', () => {
expect(email.validate(invalidWrongFormat)).rejects.toThrow();
});
it('emailValidation - invalid: no email', () => {
expect(email.validate(undefined)).rejects.toThrow();
});
it('emailValidation - invalid: empty string', () => {
expect(email.validate('')).rejects.toThrow();
});
});
Thanks for the explanation!
Eliminating async/await
passed but it's because the async errors are not caught in jest (version 23.x in this case). In this particular example, if an invalid email such as abcmail.com
is used to test, the test would still pass, which is not what we want.
I went and look again at how to test promises using async/await. I can confirm async/await
syntax does not work on remote as of now.
So to test promises, we can use the non async/await syntax like following:
import email from './emailValidation';
describe('emailValidation()', () => {
const valid = 'abc@gmail.com';
const invalidWrongFormat = 'asdsadasd';
it('emailValidation - valid', () => {
expect.assertions(1);
return expect(email.validate(valid)).resolves.toBe(valid);
});
it('emailValidation - invalid: wrong email format', () => {
expect.assertions(1);
return expect(email.validate(invalidWrongFormat)).rejects.toThrow();
});
it('emailValidation - invalid: no email', () => {
expect.assertions(1);
return expect(email.validate(undefined)).rejects.toThrow();
});
it('emailValidation - invalid: empty string', () => {
expect.assertions(1);
return expect(email.validate('')).rejects.toThrow();
});
});
Context
Is it normal to be able to pass tests on local but when exported? It also mentions here that all tests must pass to successfully tag. I have created, tested then exported a simple component but it keeps failing on remote repo
Expected Behavior
Actual Behavior
Steps to Reproduce the Problem
bit add src/forms/validations/emailValidation.ts -t 'src/forms/validations/emailValidation.test.ts' --id forms/validations
bit tag forms/validations 0.0.1 --message "Add email validation"
bit export <scopename>
Files
.bitmap
bit.json
Specifications