-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Converted Q Unit tests to Mocha Tests #1301
base: main
Are you sure you want to change the base?
Conversation
These tests are falling because of the changes done in init.js file, I am fixing that right now |
Signed-off-by: THEBOSS0369 <[email protected]>
…ix-js into con-mocha-backup
@THEBOSS0369 Thank you very much for this, that's great! I'll take a look as soon as I can. Looks like a great improvement. @audiodude maybe you have some comments? |
I've done some basic tests by switching to the PR/branch, running npm install, and npm run test-unit and test-unit-coverage. Congratulations, this is very impressive conversion work! Just quickly, I noticed that running these commands create a bunch of temporary files in the Repo that have not been correctly ignored (see screenshot). If the coverage files are overwritten on each coverage run, then they can remain, but you should .gitignore the coverage folder. Regarding the .nyc_output folder, it should also be .gitignore'd, but these look like files with a PID, and so I imagine will be created every run and could become a nuisance in that folder. Ignoring the folder may not be enough. Please check if there is a way to prevent them being generated, or whether they get auto-cleaned up (which would be fine). |
I haven't yet reviewed the code itself. |
@Jaifroid Sir the temp files that you are seeing is not from the code instead it is due to the command This is a blog for a reference https://zinserjan.github.io/mocha-webpack/docs/guides/code-coverage.html |
Yes, I was aware that these reports were from running the command, but we don't want them being accidentally pushed to the server by a dev, so the folders containing them should at least be added to |
Got it sir i will do it, and yes right now it just shows the table's heading and empty value I wanted to confirm whether this feature is needed or not so i created as an example. Once conversion work of test is approved, I will make it working. |
Hey @Jaifroid sir let me know what to do further in this pr, when you get some time. |
Thanks! I noticed fallback errors in the test run due to Fetch not being supported in the test environment (see screenshot): To avoid this, we should add a test for 'Fetch' support in the files
Add this specifically on these lines: |
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.
@THEBOSS0369 It's looking good. Just some minor suggestions to clean up the output display.
tests/unit/spec/mocha.test.js
Outdated
}); | ||
|
||
describe('Environment', function () { | ||
it('Mocha Test should be properly configured', function () { |
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 think it's otiose to write "should" in every test. More usual would be to write simply Configure Mocha Test
. If it has a tick, then it passed, if it has a red cross, it failed.
tests/unit/spec/mocha.test.js
Outdated
expect('test').to.equal('test'); | ||
}); | ||
|
||
it('should have loaded archive files', function () { |
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.
Similarly here, simply Load archive files
...
tests/unit/spec/mocha.test.js
Outdated
}); | ||
|
||
describe('Utils', function () { | ||
it('should correctly read an IEEE_754 float from 4 bytes', function () { |
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.
Here: Correctly read an .....
tests/unit/spec/mocha.test.js
Outdated
expect(float).to.equal(-118.625); | ||
}); | ||
|
||
it('should handle upper/lower case variations', function () { |
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.
Here Handle upper/lower case variation
{ input: 'téléphone', expected: 'Téléphone', description: 'The first letter should be uppercase' }, | ||
{ input: 'Paris', expected: 'paris', description: 'The first letter should be lowercase' }, | ||
{ input: 'le Couvre-chef Est sur le porte-manteaux', expected: 'Le Couvre-Chef Est Sur Le Porte-Manteaux', description: 'The first letter of every word should be uppercase' }, | ||
{ input: 'épée', expected: 'Épée', description: 'The first letter should be uppercase (with accent)' }, | ||
{ input: '$¥€"«xριστός» †¡Ἀνέστη!"', expected: '$¥€"«Xριστός» †¡ἀνέστη!"', description: 'First non-punctuation/non-currency Unicode letter should be uppercase, second (with breath mark) lowercase' }, | ||
{ input: 'Καλά Νερά Μαγνησία žižek', expected: 'ΚΑΛΆ ΝΕΡΆ ΜΑΓΝΗΣΊΑ ŽIŽEK', options: 'full', description: 'All Unicode letters should be uppercase' } |
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.
In these cases, it's OK to keep "should".
tests/unit/spec/mocha.test.js
Outdated
}); | ||
}); | ||
|
||
it('should remove parameters from URLs', function () { |
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.
Just Remove parameters from URLs
tests/unit/spec/mocha.test.js
Outdated
}); | ||
|
||
describe('ZIM initialization', function () { | ||
it('should set archive as ready', function () { |
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.
For this and all other "should" below, just change to, e.g., Set archive as ready
(etc.).
Signed-off-by: THEBOSS0369 <[email protected]>
@Jaifroid Thanks you for this sir , this was such a help i was trying to fix this in files |
Progress status: I'm currently trying to fix npm run test-unit-coverage isse. Its taking longer than i expected it to plus my winter's holiday has ended 2 weeks ago so i am not getting enough time to focus only on fixing it but i will try to fix it till this weekend, if i ain't able to make it, i will probably won't add the feature in this pr. would that be fine sir? @Jaifroid |
Thanks for the update. See what you can do this weekend, and if it's too complicated, maybe you could just make it into a separate issue to "Add Unit test coverage". |
Signed-off-by: THEBOSS0369 <[email protected]>
Hello @Jaifroid sir i have fixed it but its creating so many problems in other workflow of the repo's. First is that the main test are failing if i add the functionality it shows error message in files like coverage report are showing but with error messages I am not very confident with this so i am just commiting the code to show you. I am just confirming again that i should remove this functionality from this pr and go ahead with the creating an issue or should i work on it more. Its just keep getting complicated & more complicated and i don't want to mess with the codebase. Let me know what to do thanks. |
I will revert the recent commit once you have taken a look |
tests/unit/coverage-setup.cjs
Outdated
@@ -0,0 +1,26 @@ | |||
const { createInstrumenter } = require('istanbul-lib-instrument'); | |||
const { resolve } = require('path'); | |||
const { readFileSync } = require('fs'); |
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.
@THEBOSS0369 We're not using CommonJS modules. You should only use the ES Module import
statements.
.babelrc
Outdated
@@ -0,0 +1,4 @@ | |||
{ | |||
"presets": ["@babel/preset-env"], | |||
"plugins": ["@babel/plugin-transform-modules-commonjs"] |
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.
@THEBOSS0369 Don't transform modules to CJS format, that will lead to loads of issues.
@THEBOSS0369 I didn't review the whole of the latest commit, but I immediately noticed you're using the wrong type of modules. We use ES6 Modules, with Overall, my view is that you should revert the code coverage commit and make it into a separate issue. It's enough that you've converted our ancient tests to a modern format. We know the coverage is extremely poor currently, and we need to work on adding more tests for basic units of code. Being told on each run that our coverage is poor won't really help the situation, even though it's a good idea in principle! Many thanks! |
This reverts commit 444e215.
Got it sir i have reverted the changes and yess i have been searching out the internet to make it work from last 2 weeks as i have never worked on something like this before 😅🫠. |
Thanks, @THEBOSS0369 🙏. I shall review ASAP. |
This PR Fixes #1187
Description
In this PR i have converted Q Unit tests to Mocha Tests.
Tests Converted
All the tests from
unit/spec/test.js
file are converted into mocha tests. It can be found inunit/spec/mocha.test.js
Note:
In this PR i haven't deleted the test.js file as once other files are approved we can continue with deleting that file
Commands to Run the test:
npm run test-unit
: This command runs the unit tests for the application to ensure that individual units of code (such as functions or methods) are working as expected.npm run test-unit-watch
: This command allows us to continuously run tests while we work on our code. If we change a test file or the code it tests, Mocha will automatically re-run the tests.npm run test-unit-coverage
: This command runs the unit tests with code coverage reporting using NYC, which is a tool for generating code coverage reports.Test
I have done all the necessary test
npm test
no issuetests-e2e-firefox
-> All tests Passed.Screenshot for converted tests Passing