-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: make mocha self-contained with the source map support #913
Conversation
4b66ead
to
56fc63b
Compare
Can we converge back |
56fc63b
to
cc2333c
Compare
@shimks I consolidated it back to |
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/build
package
PTAL
package.json
Outdated
@@ -41,7 +39,7 @@ | |||
"build:full": "npm run clean:full && npm run bootstrap && npm run build && npm run mocha && npm run lint", | |||
"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.
@@ -35,7 +35,7 @@ | |||
<% } -%> | |||
"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
@@ -54,7 +55,7 @@ | |||
}, | |||
"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
@@ -6,18 +6,18 @@ | |||
"node": ">=6" | |||
}, | |||
"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.0
and 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 |
@@ -631,6 +633,15 @@ describe('Inspector for design time metadata', () => { | |||
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 test
for individual packages.mocha
command for each package and it depends on theglobal installation of
mocha
--require source-map-support/register
cannot beresolved.
The PR adds
lb-mocha
command so that we can configuresource-map-support
correctly along with other options. No global mocha installation is needed.
Checklist
npm test
passes on your machinepackages/cli
were updatedpackages/example-*
were updated