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

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.

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 .

Analyse Javascript/Typescript project with SonarCloud and Azure DevOps

I have a project containing both Javascript and Typescript files. I'm using SonarCloud to analyse this project from an Azure DevOps pipeline.
I set the task Prepare Analysis Configuration in my build pipeline like this:
- task: SonarCloudPrepare#1
inputs:
SonarCloud: 'Sonarcloud'
organization: 'MyOrg'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: 'My key'
cliProjectName: 'My name'
cliSources: '.'
When running the pipeline, I have the following error in my pipeline on Sonar Cloud Analyze step
INFO: Found 1 tsconfig.json file(s): [/home/vsts/work/1/s/tsconfig.json]
##[error]ERROR: Cannot find module 'typescript'
##[error]ERROR: TypeScript dependency was not found and it is required for analysis.
ERROR: Install TypeScript in the project directory or use NODE_PATH env. variable to set TypeScript location, if it's located outside of project directory.
ERROR: TypeScript dependency was not found and it is required for analysis.
ERROR: Install TypeScript in the project directory or use NODE_PATH env. variable to set TypeScript location, if it's located outside of project directory.
##[error]ERROR: Missing TypeScript dependency
The analysis works well for javascript files but not for typescript files. I have the typescript package installed as dev dependency in my package.json but it seems it is ignored by SonarCloud.
The documentation and topics I found are related to SonarQube version but I can't figure out how to setup this with SonarCloud.
By default, node_modules folder in local project folder won't be added into source control if you're using Visual Studio.
And this error would occur since Run Code Analysis task can't find the dependency packages defined in your package.json file. My reproducible step:
Then I add one npm install task before Prepare Analysis task to install missing packages:
NodeJS is my project name. Also in Devops repos, this is the name of the folder where package.json exists.
Then this issue went away in my pipeline:
Hope it also helps for your issue :)
In addition: You can also choose to add local node_modules folder into source control if you want. But this is not recommended in Azure Devops Service.

Error: Unknown argument 'idea-shell'

I'm using Intellij Idea community edition. When I run
new https://github.com/sbt/scala-seed.g8
or
new PlayFramework/play-scala-seed.g8
from sbt shell it gives me following error :
Error: Unknown argument 'idea-shell' g8 0.7.2 Usage: giter8 [options] <template> <template> git or file URL, or github user/repo -b, --branch <value> Resolve a template within a given branch -f, --force Force overwrite of any existing files in output directory --version Display version number
--paramname=paramval Set given parameter value and bypass interaction EXAMPLES Apply a template from github
g8 foundweekends/giter8 Apply using the git URL for the same template
g8 git://github.com/foundweekends/giter8.git Apply template from a remote branch
g8 foundweekends/giter8 -b some-branch Apply template from a local repo
g8 file://path/to/the/repo Apply given name parameter and use defaults for all others.
g8 foundweekends/giter8 --name=template-test
This happens due to how the sbt shell is implemented in the IntelliJ Scala plugin. Also the new command isn't really meant to be run from a live shell session.
Run new from the terminal instead:
sbt new https://github.com/sbt/scala-seed.g8
You should use it from the terminal like:
sbt new scala/scala-seed.g8
If you still have problems:
Maybe you have to run it from a directory that is not a SBT project (no build.sbt)
Of course you need sbt installed.

Issue when using Angular CLI ng e2e and passing both --config and --specs options

I have several Protractor config files with various configurations, for example; local and remote execution.
I have created a folder within the application root, which holds all additional protractor config files. I've left the standard protractor.conf file in the application root folder.
The specs are contained in the e2e folder contained in the application root.
As well as specifying the config to execute, I also need to specify which specs to execute at specific build steps during CI builds.
I am running the command from the application root folder, which contains the angular-cli.json file.
When I use both --config and --specs options with the following command:
ng e2e --config protractor-config\protractor-remote.conf --specs e2e\login.e2e-spec.ts
The config file is found however; it seems no specs are found:
Executed 0 of 0 specs SUCCESS in 0.002 sec.
If I only use the --config option with the below command, all specs contained in the chosen protractor config file run to completion as expected:
ng e2e --config protractor-config\protractor-remote.conf
If I only use the --specs option with the below command, the specs specified in the command run to completion as expected:
ng e2e --specs e2e\login.e2e-spec.ts
I appreciate any guidance,
Thanks
I've found the argument passed for the --specs option is relative to the directory of the config file being executed whereas the argument passed to the --config option is relative to the current working directory. I can't find this stated in the current Angular CLI documentation.
For example, in the case above when passing the argument for the --specs option, I had to navigate up one directory to the application root folder using ..\
The following command worked:
ng e2e --config protractor-config\protractor-remote.conf --specs ..\e2e\navigation.e2e-spec.ts

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