Jasmine with Coffeescript Unexpected string Syntax error - javascript

I'm trying Jasmine in Coffeescript but when i call jasmine in the terminal, I get this error:
/home/luca/tries/sourcemaps-demo/spec/mainSpec.coffee:1
nction (exports, require, module, __filename, __dirname) { describe 'A suite',
^^^^^^^^^
SyntaxError: Unexpected string
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /home/luca/.nvm/v0.10.35/lib/node_modules/jasmine/lib/jasmine.js:63:5
at Array.forEach (native)
at Jasmine.loadSpecs (/home/luca/.nvm/v0.10.35/lib/node_modules/jasmine/lib/jasmine.js:62:18)
at Jasmine.execute (/home/luca/.nvm/v0.10.35/lib/node_modules/jasmine/lib/jasmine.js:145:8)
This is my spec/support/jasmine.json:
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.coffee"
],
"helpers": [
"helpers/**/*.coffee"
]
}
And this is my spec/mainSpec.coffee:
describe 'A suite', ->
it 'should return true', ->
expect(true).toBe true
I'm missing something?

jasmine does not support coffee-script. If You want to write tests in coffee-script, use jasmine-node
$npm install -g jasmine-node
$jasmine-node --coffee spec/
.
Finished in 0.01 seconds
1 test, 1 assertion, 0 failures, 0 skipped

Related

NPM is giving me an Error with every command

Whenever I'm running a command with npm. it's giving an Error. A few days ago, It was totally fine. I used it in some of my projects but now it is can't do nothing.
node:internal/modules/cjs/loader:941
const err = new Error(message);
^
Error: Cannot find module '../../package.json'
Require stack:
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\utils\\unsupported.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
]
}
The error says that npm can't find the package.json file. Make sure you haven't deleted it. If you want to create one you can use npm init to initialize one in the current directory. Even if that fails I'd reinstall node js and double check the NODE_PATH.

Error: Cannot find module '#rails/webpacker' rails 6

When I run my Rails 6.0 application on development environment I get the next trace on the development.log
[Webpacker] Compiling…
[Webpacker] Compilation failed:
/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:93
throw err;
^
Error: Cannot find module '#rails/webpacker'
Require stack:
- /mnt/config/webpack/environment.js
- /mnt/config/webpack/development.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js
- /home/alejo/rails_project/node_modules/webpack/bin/webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
at Function.Module._load (internal/modules/cjs/loader.js:847:27)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/mnt/config/webpack/environment.js:1:87)
at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/mnt/config/webpack/development.js:3:21)
at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
at requireConfig (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
at /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:71:45
at Object.parse (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:49:8
at Object.<anonymous> (/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1121:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/mnt/config/webpack/environment.js',
'/mnt/config/webpack/development.js',
'/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js',
'/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js',
'/home/alejo/rails_project/node_modules/webpack/bin/webpack.js'
]
}
I am using webpacker 4.0.7, rails 6.0.0 and ruby 2.6.5
I want to know why am I getting this error and how do I solve it.
Thank you
I ran into this issue as well. For me, the issue was the node version (13.6.0). I figured this out by running yarn add #rails/webpacker, which returned the error Expected version "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7". Got "13.6.0"
To fix it:
Update node to an appropriate version (see error above)
Delete node_modules directory
Update yarn files with yarn install --check-files
Install webpacker with rails webpacker:install
Confirm it worked by bin/webpack-dev-server and getting no errors

mocha describe 'unexpected string error'

I am writing the below test cases using Mocha in node.js. Please find the below code :
describe('Car', function() {
it('can park?',function()
{
const car = new Car();
assert.equal(car.park(),'stopped'); }); });
I am running this using following command :
npm run test
It populates following error :
> inbox#1.0.0 test /Users/abc/test/
> mocha
/Users/abc/test/Inbox.test.js:18
describe('Car', function() {
^^^^^
SyntaxError: Unexpected string
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
Can you please help me, what i am doing wrong here?
Note : package.json is also updated with mocha in scripts field.
I know i am answering to my own question but its more like recording it for others.
Just Use following statement in your code at top or before describe statements
"use strict";

UI test with mocha and coffee script

I am setting up test case environment with the help of Getting started with Selenium WebDriver for node.js
I have installed all dependencies but still unable to run sample test case given in above blog:
selenium = require 'selenium-webdriver'
chai = require 'chai'
chai.use require 'chai-as-promised'
expect = chai.expect
before ->
#timeout 10000
#driver = new selenium.Builder()
.withCapabilities(selenium.Capabilities.chrome())
.build()
#driver.getWindowHandle()
after ->
#driver.quit()
describe 'Webdriver tutorial', ->
beforeEach ->
#driver.get 'http://bites.goodeggs.com/posts/selenium-webdriver-nodejs-tutorial/'
it 'has the title of the post in the window\'s title', ->
expect(#driver.getTitle()).to.eventually.contain
'Getting started with Selenium Webdriver for node.js'
it 'has publication date', ->
text = #driver.findElement(css: '.post .meta time').getText()
expect(text).to.eventually.equal 'December 30th, 2014'
it 'links back to the homepage', ->
#driver.findElement(linkText: 'Bites').click()
expect(#driver.getCurrentUrl()).to.eventually.equal 'http://bites.goodeggs.com/'
Running above test case with:
mocha JavaScript_test.coffee --compilers coffee:coffee-script/register
I get following error:
module.js:471
throw err;
^
Error: Cannot find module 'coffee-script/register'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/mocha/bin/_mocha:337:3
at Array.forEach (native)
at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:329:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
I had the same problem, and I don't know when it change but the module coffee-script doesn't exist anymore.
The right package is coffeescript so the right command is :
mocha JavaScript_test.coffee --compilers coffee:coffeescript/register
But --compilers is deprecated so the new right syntaxe is :
mocha JavaScript_test.coffee --require coffeescript/register

Express.js Router + async/await functions Babel.js v6 (Error: Route.post() requires callback functions but got a [object Undefined])

I cannot make express router work with async/await functions with Babel v6.
It throws such error:
MacBook-Pro-Dmitri:api dmitri$ npm start
> dhhb-api#0.1.0 start /Users/dmitri/github/dhhb/api
> node bin/runServer
/Users/dmitri/github/dhhb/api/node_modules/express/lib/router/route.js:196
throw new Error(msg);
^
Error: Route.post() requires callback functions but got a [object Undefined]
at Route.(anonymous function) [as post] (/Users/dmitri/github/dhhb/api/node_modules/express/lib/router/route.js:196:15)
at Function.proto.(anonymous function) (/Users/dmitri/github/dhhb/api/node_modules/express/lib/router/index.js:510:19)
at exports.default (index.js:41:13)
at exports.default (index.js:13:28)
at Object.<anonymous> (server.js:27:16)
at Module._compile (module.js:460:26)
at loader (/Users/dmitri/github/dhhb/api/node_modules/babel-core/node_modules/babel-register/lib/node.js:130:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/dmitri/github/dhhb/api/node_modules/babel-core/node_modules/babel-register/lib/node.js:140:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/dmitri/github/dhhb/api/bin/runServer.js:4:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
My .babelrc:
{
"presets": [
"es2015",
"stage-0"
],
"plugins": [
"syntax-async-functions",
"transform-regenerator",
"transform-runtime"
]
}
Init file:
require('babel-core/register');
require('babel-polyfill');
require('../src/server.js');
And server js endpoints:
// uncomment to throw
// app.get('/test1', async function () { // will throw });
app.get('/test2', function () { // no error thrown });
UPDATE
I've setup a demo repo to replicate buggy behavior:
https://github.com/voronianski/babel-express-async-bug

Categories

Resources