How to run NX tests with verbose logging? - nrwl-nx

Running the latest version of NX and its associated dependencies:
"#nrwl/cli": "14.5.4",
"#nrwl/cypress": "14.5.4",
"#nrwl/eslint-plugin-nx": "14.5.4",
"#nrwl/jest": "14.5.4",
"#nrwl/linter": "14.5.4",
"#nrwl/nx-cloud": "latest",
"#nrwl/react": "14.5.4",
"#nrwl/storybook": "^14.5.4",
"#nrwl/web": "14.5.4",
"#nrwl/workspace": "14.5.4",
I run the following command expecting to see verbose logging for my tests:
yarn nx run-many --all --target=test --skip-nx-cache --verbose
but no logging at all appears, and the tests appear to hang without running.
Is there a way to get verbose logging running your project in NX, or is that feature currently broken?

Ran into your question when investigating how to get the results in my local terminal when running a custom target I made for npm audit via run-many. It used to only tell me that both of my projects succeded but I needed to see the results of the audits. For me, I needed to add:
--output-style=static
at the end of the run-many command.

Related

pytest-appium: cannot start tests, got SKIPPED

Trying to run tests with pytest-appium plugin.
Trying to start tests as usual, without any additional cmdline arguments:
SKIPPED [1] projects/Python/3/appium-tests/venv/lib/python3.8/site-packages/pytest_appium/plugin.py:8: no variables file
When started tests with --variables=vars.json (also added corresponding file to the project):
SKIPPED [1] projects/Python/3/appium-tests/venv/lib/python3.8/site-packages/pytest_appium/plugin.py:12: no "caps" or "server" in variables
Was trying also with caps or server or altogether in vars.json, same result:
SKIPPED [1] projects/Python/3/appium-tests/venv/lib/python3.8/site-packages/pytest_appium/plugin.py:12: no "caps" or "server" in variables
What am I doing wrong?
Your problem seems to be that you are using the wrong pytest-appium.
In PyPi, pytest-appium points to this project, which is a very basic plugin probably created for testing purposes.
The plugin you reference seems not to be released on PyPi, so you have to clone and install it from the repositiory:
pip uninstall pytest-appium # get rid of the wrong one
git clone https://github.com/GlobalRadio/pytest-appium.git
cd pytest-appium
pip install .

Angular PWA missing ngsw.json and ngsw-worker file

I have a problem with #angular/pwa. when I am building in production mode I am not getting ngsw-worker.js and ngsw.json files in my dist folder.
the pwa version am using is:
#angular/pwa: ^0.13.8
#angular/service-worker: ~7.1.0
#angular version 7
Thanks in advance
This answer is only relevant when:
you use nrwl/nx
which decorates the ng command
and angular configuration composition:
i.e. ng build client --configuration=production,variant
nx version 11
Now the workaround for version 10 (see below) does not work anymore!
closed-nx#4296: Cannot pass in multiple configurations using -c since nx 11
actual fix should be handled in: nx#2839: NX does not handle multiple configurations: nx run app:build --configuration=production,stage-env
a workaround can be to opt-out of the nx ng-cli-decorate patch
quote from nx#4452:
To opt out of this patch:
Replace occurrences of nx with ng in your package.json Remove the
script from your postinstall script in your package.json Delete and
reinstall your node_modules
nx version 10
To fix the issue (we use nx version 10) we replaced:
ng build client --configuration=production,variant with
nx build client -c=production,variant
The problem was, that nx did not pass the configuration correctly to ng and thus ng did not build the production configuration (thus no PWA/service-worker)
Links to nx issues:
#2839: NX does not handle multiple configurations: nx run app:build --configuration=production,stage-env
#4296: Cannot pass in multiple configurations using -c since nx 11
You can copy the files from the node_modules folder (from a prompt in your project folder):
cp node_modules/#angular/service-worker/ngsw-worker.js ./src/ngsw-worker.js
cp node_modules/#angular/service-worker/ngsw-config.json ./ngsw-config.json
You may also need to make sure your service worker is registered. Nice presentation on the subject at: https://javascript-conference.com/wp-content/uploads/2017/12/Automatic_Progressive_Web_Apps_using_Angular_Service_Worker_Maxim_Salnikov.pdf

Error: expected file.path to export a function or instance

I creating a generator plugin named generate-swap-project for the generate generator tool.
Let's first see:
https://github.com/generate: A new command line tool and developer framework for scaffolding out GitHub projects. A more powerful, composable, functional alternative to Yeoman.
https://github.com/generate/generate: A new command line tool and developer framework for scaffolding out GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.
https://github.com/rbecheras/generate-swap-project A generator for SWAP projects (the generator I'm working on)
https://github.com/rbecheras/generate-swap-project/tree/1-convert-to-standard-code-style: A generator for SWAP projects (the readme on master branch)
https://github.com/rbecheras/generate-swap-project/tree/1-convert-to-standard-code-style: (the readme on problematic branch)
The master branch works fine and tests pass on travis AND on local dev host.
Tests are run by the following yarn script (on master):
$ yarn test
However in the PR #2 Resolve #1 "Convert to ESNext/StandardJS code style", I made the following changes:
converted ES5 codebase to ESNext
moved codebase to src/lib and src/tests
added a generator.js file a t root level that just requires ./dist/lib/generator.js
added yarn scripts: clear + lint + build + test (cf. Readme section about the build pipeline)
Ref. to the branch 1-convert-to-standard-code-style
Tests are run by the following yarn script (on branch 1-convert-to-standard-code-style):
$ yarn travis
or (its alias)
$ yarn pipeline
that is task sequence for yarn clear && yarn lint && yarn build && yarn test
But one test fails (1 test fails for 14 test pass) with a strange error: Error: expected file.path to export a function or instance:
$ yarn pipeline
yarn run v1.3.2
$ yarn clear && yarn lint && yarn build && yarn test
$ yarn rimraf build dist
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/rimraf build dist
$ yarn lint:esnext
$ yarn standard src/*.js src/**/*.js
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/standard 'src/*.js' src/lib/generator.js src/tests/plugin.js src/tests/test.js
$ yarn build:lib && yarn build:tests && yarn build:docs
$ yarn babel src/lib/ --out-dir dist/lib --source-maps
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/babel src/lib/ --out-dir dist/lib --source-maps
src/lib/generator.js -> dist/lib/generator.js
$ yarn babel src/tests/ --out-dir dist/tests --source-maps
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/babel src/tests/ --out-dir dist/tests --source-maps
src/tests/plugin.js -> dist/tests/plugin.js
src/tests/test.js -> dist/tests/test.js
$ echo WARNING: No documentation build available yet
WARNING: No documentation build available yet
$ yarn mocha dist/tests/**/*.js
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/mocha 'dist/tests/**/*.js'
generate-swap-project
plugin
✓ should add tasks to the instance (80ms)
✓ should only register the plugin once
generate-swap-project
tasks
✓ should extend tasks onto the instance
✓ should run the `default` task with .build (186ms)
✓ should run the `default` task with .generate
swap-project (CLI)
X => 1) should run the default task using the `generate-swap-project` name (global install)
✓ should run the default task using the `swap-project` generator alias (local generator.js)
swap-project (API)
✓ should run the default task on the generator
✓ should run the `swap-project` task
✓ should run the `default` task when defined explicitly
sub-generator
✓ should work as a sub-generator
✓ should run the `default` task by default
✓ should run the `generator:default` task when defined explicitly
✓ should run the `generator:swap-project` task
✓ should work with nested sub-generators
✓ should run tasks as a sub-generator
15 passing (1s)
1 failing
1) generate-swap-project
swap-project (CLI)
should run the default task using the `generate-swap-project` name (global install):
Error: expected file.path to export a function or instance
at Env.get (node_modules/base-env/lib/file.js:256:11)
at Env.invoke (node_modules/base-env/lib/env.js:117:19)
at Generate.<anonymous> (node_modules/base-generators/lib/generator.js:62:30)
at Generate.getGenerator (node_modules/base-generators/index.js:157:22)
at Object.exports.process (node_modules/base-generators/lib/tasks.js:127:24)
at node_modules/base-generators/lib/tasks.js:86:23
at Array.reduce (<anonymous>)
at exports.parse (node_modules/base-generators/lib/tasks.js:85:15)
at Generate.generate (node_modules/base-generators/index.js:490:21)
at Generate.generate (node_modules/base-generators/index.js:463:23)
at Context.<anonymous> (dist/tests/test.js:87:11)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Here is the travis config
{
"sudo": false,
"language": "node_js",
"node_js": "lts/carbon",
"script": [
"npm link",
"npm install --global generate .",
"yarn travis"
],
"group": "stable",
"dist": "trusty",
"os": "linux"
}
And here is:
the travis failling build for the PR #2
and the log for the job running on Node LTS/Carbon (v8.y.z)
I can't understand why that test (the one that runs the generator in CLI mode) fails after ESNext convertion and babel transpilation.
What's wrong with my PR ?
That bug is indeed related to the consequences of the babel transpilation.
The file generator.js at the root level directory use CommonJS module loading, that's required by the direct call by the global generate binary.
Here is the code of ./generator.js:
module.exports = require('./dist/lib/generator')
But:
since the module ./dist/lib/generator.js is the result of a babel transpilation of ./src/lib/generator.js, that exports the generator as a default anonymous function,
and since the module ./generator.js is a CJS module and use require()
then the required module is not the exported generator function but an object which contains a property default; and the value of this property is the generator function.
Thus, the correct way to implement ./generator.js is as following:
module.exports = require('./dist/lib/generator').default
That's all!
Here is the PR that fix the issue, and here is the passing travis build for that PR.

How can I fix tests in Ember testem with errors such as 'could not load', 'failed', 'could not find module' or 'died'?

I managed to get a couple of EAK/grunt based Ember apps upgraded to 1.11 with HTMLBars, and then got them migrated to Ember CLI/Brocolli. The unit tests were setup for karma test runner so I'm looking at how to get those running in the CLI projects now, but I didn't write the tests and really have no experience with unit testing javascript modules.
Searching around the iNet, I can see that others have also used karma becasue of its coverage output and are trying to get it to work with Ember CLI, but that Ember Core isn't supporting it, though they say anyone should be able to get it set up with a custom addon. I'm also trying to use the 'testem' runner to see what sticks with that.
The Ember site does have an 'automating tests with runners' page for v1.10, with sections on 'testem' and 'karma', but it doesn't appear for v1.11 so I can't tell from that site what is or isn't relevant. But it seems like I should be able to work out a solution for the karma test runner, so I added the old devDependencies to the project package.json:
"karma": "^0.12.31",
"karma-chai": "~0.1.0",
"karma-chrome-launcher": "~0.1.2",
"karma-coverage": "~0.2.1",
"karma-firefox-launcher": "~0.1.3",
"karma-junit-reporter": "~0.2.1",
"karma-mocha": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.2",
"karma-sinon-chai": "~0.1.5"
I also dropped the old 'karma.conf.js' (along with a few other karma confs) in the project and updated the paths inside (from 'vendor' to 'bower_components'). I did find a 'ember-cli-karma' node mode and installed it, but it seems to just have a 'package.json'. It has no docs and seems like just a stubbed out starter project with no implementation. I also installed 'karma', 'karma-cli' and 'testem' node modules.
The testem docs say to add you src and test files to 'testem.json', but with out examples I don't know what that means; a list of every src and test file? With what path; relative, absolute? Forward slashes, backslashes? preceded with / or ./ or ../? I just left them out because I think the system just finds the src and tests by convention.
When I run 'karma init' I get:
readline.js:529
this.line = this.line.slice(this.cursor);
^
TypeError: Cannot read property 'slice' of undefined
When I run 'testem' I get:
TEST'EM 'SCRIPTS!
Open the URL below in a browser to connect.
http://localhost:7357/aN;0faN;NaNf
...then the project's '../tests/index.html' loads in a browser, but is not able to 'find' any of the asset files (css, js) so nothing executes or renders correctly. I just see template expressions ({{content-for 'head'}}, etc).
When I run 'ember test' I get:
Building...BuildingBuilding.Building..Building...Built project successfully.
1..0
# tests 0
# pass 0
# fail 0
# ok
No tests were run, please check whether any errors occurred in the page (ember test --server) and ensure that you have a test launcher (e.g. PhantomJS) enabled.
When I run 'ember test --server' I get:
The test index.html loaded in a browser with a test report. When I uncheck 'hide passed tests' the report indicates '29 passed, 28 failed'. It has 11 sections where a particular test may have 3 problems such as 'could not load', 'failed', 'could not find module', 'attempting to register an unknown factory' or 'died'.
With this, I'm obviously running testem and not karma, so may as well work on getting testem working and figure out karma later. If there were more examples and migration troubleshooting docs I might have a systematic way to work through some of these problems.
I ran into "No tests were run,..." problem recently after a node upgrade. I fixed it with a:
npm install -g phantomjs
This provides some additional options as well:
https://github.com/ember-cli/ember-cli/issues/3969
I had the Cannot read property 'slice' of undefined error on MS Windows, running via MSys2. I have solved it by using karma init from an ordinary cmd prompt.

Mocha Express Coffee should.equal not working

I am following a tutorial. While I run
require "should"
describe "feature", ->
it "should add two numbers", ->
(2+2).should.equal 4
And i run
mocha routes-test.coffee --compilers coffee:coffee-script
I get following errors
1) feature should add two numbers:
AssertionError: expected {} to be true
at Object.true (/home/../../coffeepress/node_modules/should/lib/should.js:251:10)
at Context.<anonymous> (/home/../../coffeepress/test/routes-test.coffee:7:28)
at Test.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:184:32)
at Runner.runTest (/usr/lib/node_modules/mocha/lib/runner.js:300:10)
at Runner.runTests.next (/usr/lib/node_modules/mocha/lib/runner.js:346:12)
at next (/usr/lib/node_modules/mocha/lib/runner.js:228:14)
at Runner.hooks (/usr/lib/node_modules/mocha/lib/runner.js:237:7)
at next (/usr/lib/node_modules/mocha/lib/runner.js:185:23)
at Runner.hook (/usr/lib/node_modules/mocha/lib/runner.js:205:5)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
What is going on here? I installed should.js ( npm install should) and mocha. Is there some syntax mistake or some setting mistakes?
Your problem is likely a mismatch between your node version and the versions of mocha and should that you used. If you used the package.json file from that tutorial exactly you would have loaded mocha 0.10.0 and should 0.5.1. When I tried the same thing with a current version of node (v0.8.1) I saw the following warnings when doing npm install:
npm WARN engine mocha#0.10.0: wanted: {"node":">= 0.4.x < 0.7.0"} (current: {"node":"0.8.1","npm":"1.1.34"})
npm WARN engine commander#0.5.1: wanted: {"node":">= 0.4.x < 0.7.0"} (current: {"node":"0.8.1","npm":"1.1.34"})
And then when I run mocha against the example test you've provided I get the same error.
Simply changing the mocha and should versions in my package.json to be
"mocha": ">=0.10.0",
"should": ">=0.5.1"
then running npm update fixed the problem and the test ran fine. You can also set those versions to "latest" or the current versions of those packages if you'd like to lock them down ("1.3.0" and "0.6.3" respectively at the time I write this).