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

fix: make mocha self-contained with the source map support #913

Merged
merged 1 commit into from
Jan 26, 2018

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Jan 25, 2018

This is a follow-up to #884.
The commit makes 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 configure source-map-support
correctly along with other options. No global mocha installation is needed.

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Related API Documentation was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in packages/example-* were updated

@shimks
Copy link
Contributor

shimks commented Jan 25, 2018

Can we converge back mocha.js.opts with mocha.ts.opts? They contain the same content and source-map-support stuff is done in run-mocha anyway

@raymondfeng
Copy link
Contributor Author

@shimks I consolidated it back to mocha.opts.

Copy link
Member

@bajtos bajtos left a 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\"",
Copy link
Member

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?

"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'",
Copy link
Member

@bajtos bajtos Jan 26, 2018

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.

Copy link
Member

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'",
Copy link
Member

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\""
}

@@ -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'"
Copy link
Member

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

@@ -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'",
Copy link
Member

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.)

@bajtos
Copy link
Member

bajtos commented Jan 26, 2018

One more comment: please update packages/build/README.md to reflect the changes you are making here. The current content does not look correct to me:

    "acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'",
    "integration": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'",
    "test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'",
    "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'",


// 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));
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 versions 0.X >=0.1.0, and no updates for versions 0.0.X.

Copy link
Contributor Author

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?

Copy link
Member

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:

#954

@bajtos
Copy link
Member

bajtos commented Jan 26, 2018

@raymondfeng when you rebase on top of recently landed #908, please update package.json in example-log-extension too.

@shimks
Copy link
Contributor

shimks commented Jan 26, 2018

When I run npm t on the monorepo, the tests in the cli/test/sandbox/test also seem to be running. Could you also fix that with this PR please?

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.
@raymondfeng
Copy link
Contributor Author

PTAL

@raymondfeng
Copy link
Contributor Author

single quotes don't work on Windows

Fixed with \".

I think lb-mocha is not available inside @loopback/build package

That's expected. That's why we only use lb-mocha for modules that have @loopback/build as a dependency.

@raymondfeng raymondfeng merged commit 7c6d869 into master Jan 26, 2018
@bajtos bajtos deleted the fix-mocha-source-map branch January 29, 2018 10:25
@@ -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', () => {
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants