-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: make mocha self-contained with the source map support #913
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
Conversation
4b66ead to
56fc63b
Compare
|
Can we converge back |
56fc63b to
cc2333c
Compare
|
@shimks I consolidated it back to |
bajtos
left a comment
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.
@raymondfeng This is awesome, I love how simpler and shorter our test-related package scripts are now 👍 And thank you for cleaning the mess I accidentally created with my previous pull request 🙇
I am afraid some of your changes are most likely breaking other things and need to be fixed:
- single quotes don't work on Windows
- I think lb-mocha is not available inside
@loopback/buildpackage
PTAL
package.json
Outdated
| "pretest": "npm run clean && npm run build:current", | ||
| "test": "node packages/build/bin/run-nyc npm run mocha", | ||
| "mocha": "node packages/build/bin/select-dist mocha --opts packages/build/mocha.ts.opts \"packages/*/DIST/test/**/*.js\" \"packages/cli/test/*.js\"", | ||
| "mocha": "node packages/build/bin/run-mocha --opts packages/build/mocha.opts \"packages/*/DIST/test/**/*.js\" \"packages/cli/test/*.js\"", |
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.
AFAICT, run-mocha is already adding --opts packages/build/mocha.opts, can you please remove --opts from this package script too?
packages/build/README.md
Outdated
| "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", | ||
| "acceptance": "lb-mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", | ||
| "integration": "lb-mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", | ||
| "test": "lb-mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", |
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. I believe lb-mocha is already adding --opts to CLI arguments.
Please make sure these scripts actually work when executed from packages/build directory. I would expect to see ./bin/run-mocha here, because it is my understanding that node_module/.bin/lb-mocha is created only when @loopback/build is installed as a (dev)dependency, which is not the case in @loopback/build itself.
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.
Also --opts ../../test/mocha/opts looks suspicious to me, isn't this path pointing to monorepo-level test folder that no longer exists? I think we should not be needed --opts at all, since lb-mocha (run-mocha) is already adding them.
| "pretest": "npm run clean && npm run build", | ||
| <% if (project.mocha) { -%> | ||
| "test": "lb-dist mocha DIST/test", | ||
| "test": "lb-mocha 'DIST/test'", |
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.
AFAIK, single quotes don't work on Windows, that's why we have to use escaped double quotes in package scripts.
{
"test": "lb-mocha \"DIST/test\""
}
packages/cli/package.json
Outdated
| "scripts": { | ||
| "prepublishOnly": "nsp check", | ||
| "test": "mocha --opts node_modules/@loopback/build/mocha.js.opts \"test/*.js\"" | ||
| "test": "lb-mocha 'test/*.js'" |
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, please preserve original double quotes here and also in all other package scripts you have modified in this patch.
See https://stackoverflow.com/q/10737283/69868 and https://stackoverflow.com/a/24181667/69868
packages/authentication/package.json
Outdated
| }, | ||
| "scripts": { | ||
| "acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'", | ||
| "acceptance": "lb-mocha 'DIST/test/acceptance/**/*.js'", |
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 change single quotes to double quotes while you are changing test-related scripts in this file. (See my other comments below for more details.)
|
One more comment: please update |
|
|
||
| // Substitute the DIST variable with the dist folder | ||
| const dist = utils.getDistribution(); | ||
| const mochaOpts = argv.slice(2).map(a => a.replace(/\bDIST\b/g, dist)); |
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.
Since this has effectively inlined select-dist script, I think we can remove select-dist entirely? Just make sure to mention that removal in the commit message as a BREAKING CHANGE.
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.
We have to leave lb-dist there to keep backward compatibility as projects generated from previous versions of our CLI reference lb-dist.
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.
Makes sense.
To me, this is another argument against using.alpha.X prereleases for so long. If we were versioning non-core modules as 0.x.y, then we could treat semver-patch release as backwards compatible and semver-minor releases as breaking. This works great with the carrot operator as implemented by npm's semver (https://www.npmjs.com/package/semver#caret-ranges-123-025-004):
this allows patch and minor updates for versions
1.0.0and above, patch updates for versions0.X >=0.1.0, and no updates for versions0.0.X.
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.
Agree with the versioning. Is it too late to fix it?
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.
Agree with the versioning.
👍
Is it too late to fix it?
I don't know. Let's open a new issue and try to find out what the implications of such change would be & how much work this change would require:
|
@raymondfeng when you rebase on top of recently landed #908, please update |
|
When I run |
This is a follow-up to #884. The changes make it impossible to run 'npm test' for individual packages. - There is no local mocha command for each package and it depends on the global installation of 'mocha' - With the global mocha, --require source-map-support/register cannot be resolved. The PR adds 'lb-mocha' command so that we can support source-map-support correctly along with other options. No global mocha installation is needed.
cc2333c to
7bc8125
Compare
|
PTAL |
Fixed with
That's expected. That's why we only use |
| expect(meta).to.eql(MyClass); | ||
| }); | ||
|
|
||
| it('inspects design time type for properties with union type', () => { |
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.
This looks like unrelated changes to me. @raymondfeng could you please check these changes were intended?
This is a follow-up to #884.
The commit makes it impossible to run
npm testfor individual packages.mochacommand for each package and it depends on theglobal installation of
mocha--require source-map-support/registercannot beresolved.
The PR adds
lb-mochacommand so that we can configuresource-map-supportcorrectly along with other options. No global mocha installation is needed.
Checklist
npm testpasses on your machinepackages/cliwere updatedpackages/example-*were updated