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

Unstubbed console.log/error/warn() should throw in tests #1996

Closed
Reinmar opened this issue Aug 26, 2019 · 7 comments
Closed

Unstubbed console.log/error/warn() should throw in tests #1996

Reinmar opened this issue Aug 26, 2019 · 7 comments
Assignees
Labels
type:task This issue reports a chore (non-production change) and other types of "todos".

Comments

@Reinmar
Copy link
Member

Reinmar commented Aug 26, 2019

Extracted from #1970

Make sure we throw on console.log/error() in the tests. Not sure how, but I guess we can load some file which overrides them as the very first test (just add it in the karma's config). There may be a more "standard" way to do so too.

Then:

Make sure all tests pass after the above.

@Reinmar Reinmar added status:confirmed type:task This issue reports a chore (non-production change) and other types of "todos". labels Aug 26, 2019
@Reinmar Reinmar added this to the iteration 27 milestone Aug 26, 2019
@Reinmar
Copy link
Member Author

Reinmar commented Aug 26, 2019

After @ma2ciek:

Make sure we throw on console.log/error() in the tests. Not sure how, but I guess we can load some file which overrides them as the very first test (just add it in the karma's config). There may be a more "standard" way to do so too.

I've tried the following added to the entry file of the automated tests and it's been working well:

beforeEach( () => {
	console.log = log => { originalWarn( 'Detected \`console.log()\`:' ); throw new Error( log ); };
	console.warn = warn => { originalWarn( 'Detected \`console.warn()\`:' ); throw new Error( warn ); };
	console.error = error => { originalWarn( 'Detected \`console.error()\`:' ); throw new Error( error ); };
} );

Although, shouldn't this behavior be configurable, e.g. consoleAllowed defaulted to false? I can imagine someone crying when debugging a broken test 😄

@Reinmar
Copy link
Member Author

Reinmar commented Aug 26, 2019

Although, shouldn't this behavior be configurable, e.g. consoleAllowed defaulted to false? I can imagine someone crying when debugging a broken test 😄

Doh, I didn't think about this ;O

Let's ask the team.

@Reinmar
Copy link
Member Author

Reinmar commented Aug 26, 2019

I'm actually thinking that perhaps we should have --disallow-console-us and use it on CI. When running tests locally most of the time you're actually working on something and will use the console. At least, that's how I work.

@jodator
Copy link
Contributor

jodator commented Aug 26, 2019

I was going to write that I like the --allow-console more as it will fail faster locally (so before submitting a PR) but the --disallow-console-use would be less troublesome when working locally. We might need to remember about running tests with --disallow-console-use before submitting a PR.

@Reinmar
Copy link
Member Author

Reinmar commented Sep 11, 2019

To be clear, the final result should be resolving the issue described in #2038 once and for all.

@ma2ciek
Copy link
Contributor

ma2ciek commented Sep 19, 2019

Actually, I wasn't 100% sure if I should test these console warns or not. In the --no-debug environment these tests would break because the console.warn() code would be still commented out.

The other thing is the weird Travis behavior - take a look at the latest master ckeditor5-engine test logs - https://travis-ci.org/ckeditor/ckeditor5-engine/builds/586428795 - there's no warning in the Chrome part, while they appear in the FF tests and on local Chrome as well.

mlewand added a commit to ckeditor/ckeditor5-engine that referenced this issue Sep 23, 2019
mlewand added a commit to ckeditor/ckeditor5-utils that referenced this issue Sep 23, 2019
mlewand added a commit to ckeditor/ckeditor5-paste-from-office that referenced this issue Sep 23, 2019
mlewand added a commit to ckeditor/ckeditor5-dev that referenced this issue Sep 23, 2019
@ma2ciek
Copy link
Contributor

ma2ciek commented Sep 25, 2019

The above PRs fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:task This issue reports a chore (non-production change) and other types of "todos".
Projects
None yet
Development

No branches or pull requests

3 participants