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).
Related
i`m trying to run the very basic flow:
1) install tools:
npm install -g pulp bower
Pulp version 12.2.0
purs version 0.12.0 using C:\Users\panda.psvm\current\bin\purs.EXE
C:\Users\panda>bower --version
1.8.4
2) following steps from this answer i installed purs https://stackoverflow.com/a/50554135/1358421
C:\Users\panda>purs --version
0.12.0
Ok, lets create a project.
c:\home\projects\sandbox\purr>mkdir hello-purr
c:\home\projects\sandbox\purr>cd hello-purr
c:\home\projects\sandbox\purr\hello-purr>
pulp init
c:\home\projects\sandbox\purr\hello-purr>pulp init
* Generating project skeleton in c:\home\projects\sandbox\purr\hello-purr
bower purescript-console#* cached https://github.com/purescript/purescript-console.git#4.1.0
bower purescript-console#* validate 4.1.0 against https://github.com/purescript/purescript-console.git#*
bower purescript-prelude#* cached https://github.com/purescript/purescript-prelude.git#4.0.0
bower purescript-prelude#* validate 4.0.0 against https://github.com/purescript/purescript-prelude.git#*
bower purescript-prelude#^4.0.0 cached https://github.com/purescript/purescript-prelude.git#4.0.0
bower purescript-prelude#^4.0.0 validate 4.0.0 against https://github.com/purescript/purescript-prelude.git#^4.0.0
bower purescript-effect#^2.0.0 cached https://github.com/purescript/purescript-effect.git#2.0.0
bower purescript-effect#^2.0.0 validate 2.0.0 against https://github.com/purescript/purescript-effect.git#^2.0.0
bower purescript-console#^4.1.0 install purescript-console#4.1.0
bower purescript-prelude#^4.0.0 install purescript-prelude#4.0.0
bower purescript-effect#^2.0.0 install purescript-effect#2.0.0
purescript-console#4.1.0 bower_components\purescript-console
├── purescript-effect#2.0.0
└── purescript-prelude#4.0.0
purescript-prelude#4.0.0 bower_components\purescript-prelude
purescript-effect#2.0.0 bower_components\purescript-effect
└── purescript-prelude#4.0.0
bower purescript-psci-support#* cached https://github.com/purescript/purescript-psci-support.git#4.0.0
bower purescript-psci-support#* validate 4.0.0 against https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#^4.0.0 install purescript-psci-support#4.0.0
purescript-psci-support#4.0.0 bower_components\purescript-psci-support
├── purescript-console#4.1.0
├── purescript-effect#2.0.0
└── purescript-prelude#4.0.0
Skeleton of project successfully generated.
Trying to run it:
pulp run
* Building project in c:\home\projects\sandbox\purr\hello-purr
Error 1 of 2:
in module Main
at src\Main.purs line 4, column 1 - line 4, column 31
Module Control.Monad.Eff was not found.
Make sure the source file exists, and that it has been provided as an input to the compiler.
See https://github.com/purescript/documentation/blob/master/errors/ModuleNotFound.md for more information,
or to contribute content related to this error.
Error 2 of 2:
in module Main
at src\Main.purs line 5, column 1 - line 5, column 48
Module Control.Monad.Eff.Console was not found.
Make sure the source file exists, and that it has been provided as an input to the compiler.
See https://github.com/purescript/documentation/blob/master/errors/ModuleNotFound.md for more information,
or to contribute content related to this error.
* ERROR: Subcommand terminated with exit code 1
No luck :(
pulp test
pulp build
The same errors - It can`t find modules.
Did i miss something? Please, advice.
Thanks
Purescript 0.12 pulls in newer versions of the Effect and Console libraries, unfortunately pulp init has not yet been updated to correct the generated example to match (see https://github.com/purescript-contrib/pulp/issues/337)
just update the code in Main.purs to:
module Main where
import Prelude (Unit)
import Effect
import Effect.Console (log)
main :: Effect Unit
main = do
log "Hello sailor!"`
to get started.
Found solution.
don't need bower at all
instead, there is a psc-package (another package manager)
it didn't installed correctly on my Windows 10 with npm install -g psc-package
there was no psc-package.exe file in directory ${username}\AppData\Roaming\npm\node_modules\psc-package\vendor
So, you need to fix install.js file and replace
ignore: ['psc-package']
with
ignore: [bin.use()]
then run fixed installation with
${username}\AppData\Roaming\npm\node_modules\psc-package\lib> node install
after that, In the vendor folder you may find psc-package.exe
Then, i followed this tutorial:
https://github.com/justinwoo/purescript-0.12.0-hello-world
and
Build successful.
look, show on Record:
{ apple: "banana" }
I'm new to Purescript and am following the tutorial for installation. Purescript itself is working and I can start the CLI using pulp psci, but installing purescript-list runs into trouble.
Having entered the command bower install purescript-lists --save, I get a long list of package names, but when it gets to purescript-eff and purescript-prelude I run into some version conflicts:
bower purescript-eff#^2.0.0 cached https://github.com/purescript/purescript-eff.git#2.0.0
bower purescript-eff#^2.0.0 validate 2.0.0 against https://github.com/purescript/purescript-eff.git#^2.0.0
Unable to find a suitable version for purescript-eff, please choose one by typing one of the numbers below:
1) purescript-eff#^1.0.0 which resolved to 1.0.0 and is required by purescript-console#1.0.0
2) purescript-eff#^2.0.0 which resolved to 2.0.0 and is required by purescript-st#2.0.0
Prefix the choice with ! to persist it to bower.json
? Answer
A similar message is shown for purescript-prelude. No matter which options I choose, both pulp build and pulp run fail with:
$ pulp build
* Building project in /Developer/purescript/training1
Error found:
in module PSCI.Support
at /Developer/purescript/training1/bower_components/purescript-psci-support/src/PSCI/Support.purs line 10, column 34 - line 10, column 53
Cannot import value unsafeInterleaveEff from module Control.Monad.Eff.Unsafe
It either does not exist or the module does not export it.
See https://github.com/purescript/purescript/wiki/Error-Code-UnknownImport for more information,
or to contribute content related to this error.
Compiling PSCI.Support
* ERROR: Subcommand terminated with exit code 1
What have I missed here?
Thanks
Chris W
If you are using psc version 0.10.* you should go with prelude, lists and eff v2*.
If you are using psc version 0.9.* you should go with prelude, lists and eff v1*.
If you are using psc 0.10.* you might want to update pulp to version 9.1.0
The problem occurs due to breaking changes between psc 0.9 and 0.10 and the relevant libraries. by writing bower install purescript-lists --save you are asking bower for the latest dependencies which conflict with the dependency versions specified in your bower.json.
I'm having trouble finding the correct way to use babel to allow me to use jsx in serverside.
Node-jsx was deprecated for babel. It seems like babel-core/register is whats supposed to be used but I still get unexpected token issues.
I created a repo with the problem im having.
https://github.com/pk1m/Stackoverflow-helpme
When I run node app or npm run watch-js I keep getting unexpected token referring to the JSX code '<'.
How do I get babel to transpile JSX, or am I completely off, thanks.
You need to use babel-register (npm i babel-register --save). And run on your server:
require('babel-register')({
stage: 0
});
You can omit stage 0 if you aren't using experimental babel features. Also you might prefer to put those options in .babelrc instead.
Note that it will only work for files required AFTER calling that (so it would not have an effect on the file you include it in).
You could also have the presets and other options in a .babelrc file.
For babel 6x:
npm i babel-register babel-preset-es2015 babel-preset-react --save
require('babel-register')({
presets: ['es2015', 'react']
});
Note: there are also stage 0-2 presets.
For watching as you've written in your package.json you could try a CLI command like the one facebook are suggesting in the note here (or use webpack):
babel --presets react es2015 --watch app/ --out-dir build/
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.
I have a project that uses "coffee-script": "^1.7.1" in its package.json.
The code has this line in it:
[{id: id, name: name}, ...] = result.rows
This compiles fine using coffeescript version 1.7.1
The problem is that I am trying to use mocha for unit tests and it gives me an error on this line:
Parse error on line xyz: Unexpected '...'
Apparently mocha uses an older coffeescript. Is there a way to make it work without adjusting the source for mocha?
EDIT:
my Gruntfile.coffee:
'use strict'
module.exports = ->
#initConfig
cafemocha:
src: ['test/*.coffee']
options:
reporter: 'spec'
ui: 'bdd'
coffee:
compile:
files:
'lib/mylib.js': ['src/*.coffee']
#loadNpmTasks 'grunt-cafe-mocha'
#loadNpmTasks 'grunt-contrib-coffee'
#registerTask 'default', ['coffee', 'cafemocha']
I added mocha.opts to the test directory:
--require coffee-script/register
--compilers coffee:coffee-script/register
--reporter spec
--ui bdd
but, still, when I run grunt, it gives me the same error. I am new to this environment, and I find it too complicated, please help.
Starting from version 1.7.x CoffeeScript compiler should be explicitly registered (see change log for version 1.7.0).
So, the problem is that CoffeeScript compiler is not registered when you're running your mocha tests, so node.js treats all your .coffee files as .js files.
The best possible solution is to specify --compilers option for your mocha tests:
--compilers coffee:coffee-script/register
If you don't want to include it to every mocha call, you could set it up using mocha.opts file.
Here are some useful links:
issue about it on github
reference in mocha docs
the reason behind this breaking change in CoffeeScript engine
Update
Looks like your issue is much deeper then I thought.
First, grunt-cafe-mocha doesn't respect mocha.opts because it's running tests by requireing mocha as a dependency, instead of calling mocha test runner.
So, it would've been enough to add require('coffee-script/register') to the top of your gruntfile, if not for this old grunt issue.
In short, grunt uses coffee-script 1.3.x, forcing all its tasks to use the same version of coffee. I had the same problem with grunt-contrib-connect, being unable to use latest coffee-script in my express app.
So, the only help I can offer you is a small grunt task I wrote to solve similar problem in one of my projects. It runs mocha in a separate child process, thus completely isolating it from grunt.
N.B. I had a thought about releasing this task to npm, but considered it too minor.