jasmineNodeOpts: Unexpected identifier error while executing protractor protractorConfig.js - javascript

This is my config.js file -
//server config information
var serverConfig=require('./serverConfig.js').serverConfig;
var $browser= serverConfig.$browser;
//got the browser name
process.argv.forEach(function (val, index) {
if(val==='-browser'){
$browser=process.argv[index+1];
}
});
// !!! update the server config
serverConfig.$browser= $browser;
//config
//browser.driver.manage().timeouts().setScriptTimeout(TIME_OUT);
// The main suite of Protractor tests.
exports.config = {
seleniumServerJar: '../../selenium/selenium-server-standalone-2.37.0.jar',
chromeDriver: '../../selenium/chromedriver.exe',
seleniumAddress: serverConfig.SELENIUMN_ADDRESS,
// Spec patterns are relative to this directory.
specs: [
'../e2e/Regression/CreateOperatorViewFromViewManagement.js'
],
capabilities: {
'browserName': $browser
},
onPrepare:'../prepareStartup.js',
//When the angular bootstrap not from the <html></html>
rootElement: 'body>div',
baseUrl: serverConfig.BASE_URL
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
I get this error when I try to execute my tests using this config.js file -
C:\TRUNK\tests\func\gui\protractor\config\protractorConfig.js:60
jasmineNodeOpts: {
^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
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 ConfigParser.addFileConfig (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:139:20)
at Object.init (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\launcher.js:59:7)
at Object.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\cli.js:118:23)
at Module._compile (module.js:456:26)
When I execute protractor --help I get following options -
Options:
--help Print Protractor help menu
--version Print Protractor version
--browser, --capabilities.browserName Browsername, e.g. chrome or firefox
--seleniumAddress A running seleium address to use
--seleniumServerJar Location of the standalone selenium jar file
--seleniumPort Optional port for the selenium standalone ser
--baseUrl URL to prepend to all relative paths
--rootElement Element housing ng-app, if not html or body
--specs Comma-separated list of files to test
--exclude Comma-separated list of files to exclude
--verbose, --jasmineNodeOpts.isVerbose Print full spec names
--stackTrace, --jasmineNodeOpts.includeStackTrace Print stack trace on error
--params Param object to be passed to the tests
--framework Test framework to use. jasmine or mocha.
Please suggest what mistake I'm making in the config file or do I need to configure some more things.

You forgot a comma at the end of baseUrl: serverConfig.BASE_URL ;)
It should be:
baseUrl: serverConfig.BASE_URL,

Related

firebase cloud function deploy glob error

When deploying my cloud functions using the command firebase deploy I am getting this error for all of my functions:
! functions[deleteGame-DeleteGameFunction(us-central1)]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'glob'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/index.js:11:14)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
This is my index.js file (I got it from here):
'use strict';
/** EXPORT ALL FUNCTIONS
*
* Loads all `.f.js` files
* Exports a cloud function matching the file name
* Author: David King
* Edited: Tarik Huber
* Based on this thread:
* https://github.com/firebase/functions-samples/issues/170
*/
const glob = require("glob");
const camelCase = require("camelcase");
const files = glob.sync('./**/*.f.js', { cwd: __dirname, ignore:
'./node_modules/**'});
for(let f=0,fl=files.length; f<fl; f++){
const file = files[f];
const functionName = camelCase(file.slice(0, -5).split('/').join('_')); //
Strip off '.f.js'
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME ===
functionName) {
exports[functionName] = require(file);
}
}
This index.js file is a way to organize your firebase cloud functions that I found on https://postmarkapp.com/blog/sending-transactional-emails-via-firebase-and-cloud-functions that got it from https://codeburst.io/organizing-your-firebase-cloud-functions-67dc17b3b0da
Thank you for your help!
It sounds like you need to run this from your functions directory:
npm install glob
And probably also
npm install camelcase
You can't require a module without first installing it into your project like this.

I'm getting Cannot find module 'protractor-jasmine2-html-reporter'

i tried to generate reports by using "'protractor-jasmine2-html-reporter'", but i'm getting module not found exception with error code 5..i tried the somany solutions gathered from stack overflow, but it is not worked. can somebody please help me in this.
Config.js
var Jasmine2HtmlReporter=require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect : true,
capabilities:{
'browserName':'chrome'
},
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['ProtractorTest/PageObjectMain.js'],
jasmineNodeOpts:{
defaultTimeoutInterval : 30000
},
onPreapre:function(){
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath:"./test-results/report"
}));
},
}
Error log
[14:54:53] E/configParser - Error code: 105
[14:54:53] E/configParser - Error message: failed loading configuration file ReportConfig.js
[14:54:53] E/configParser - Error: Cannot find module 'protractor-jasmine2-html-reporter'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (H:\workspace\Protractor_tutorials\ReportConfig.js:1:88)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
and my 'Package.Json' not have any details about the report files.. so if that is the problem, please help me to how to configure those in json file.
There are few things you have to make sure while using Protractor Reporters
1.in my case, in the time creating variable for reporter instead of directly passing Reporter name try to pass the full path of Reporter module.. may this will work
Eg :
var Jasmine2HtmlReporter=require('C:/......./npm-modules/protractor-jasmine2-html-reporter');
2.make sure you running the Correct Configuration file having .js extension.
Installing without save-devworked for me .
Installed globally
npm install -g protractor-jasmine2-html-reporter
Run below command to link protractor and jasmine2-html-reporter to aovid report not generating issue. Please see Girish Sortur's answer in How to create Protractor reports with Jasmine2
npm link protractor-jasmine2-html-reporter
Also add this import with path to exact node module to avoid the error in windows 10
var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
Full conifg,js that worked for me in windows 10 as per below.
//protractor jasminreporterconfig.js
//Add this import with path to exact node module to avoid the error
var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
exports.config = {
framework: 'jasmine',
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--start-maximized" ]
}
},
onPrepare: function() {
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
takeScreenshots: true,// By default this is enabled Default is true
takeScreenshotsOnlyOnFailures: false, // Default is false (So screenshots are always generated)
cleanDestination: true, // if false, will not delete the reports or screenshots before each test run.Default is true
showPassed: true,//default is true This option, if false, will show only failures.
fileName: 'MyRepoDemo', //We can give a prefered file name .
savePath: 'myproreports',//Reports location it will automatically generated
screenshotsFolder: 'screenshotsloc' //Screenshot location it will create a folder inside myproreports
})
);
},
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['src/com/sam/scriptjs/nonangularstackscript.js']
}
It looks like You haven't installed protractor-jasmine2-html-reporter
Go to folder where packages are installed (node_modules folder) and run:
npm install protractor-jasmine2-html-reporter
Try to check where the node_modules directory is present by running npm audit and which npm commands. The main thing is path where node_modules is installed should be traced and the new module like npm install protractor-jasmine2-html-reporter can be installed in that path

How to use preact-compat with server side rendering in rollup + buble setup?

I have a preact app which is using rollup + buble. I need to use another component text-mask which uses React. I am trying to create alias within my rollup build file. For the client side, it works flawlessly however when building on the server side, it fails. My plugin section within my rollup build config is as below :-
plugins: [
alias({
'react': path.resolve('./node_modules/preact-compat/dist/preact-compat.es.js'),
'react-dom': path.resolve('./node_modules/preact-compat/dist/preact-compat.es.js')
}),
nodeResolve({ jsnext: true, browser: true }),
commonjs({ include: ['node_modules/**'], namedExports: { 'preact-redux': ['connect', 'Provider'] } }),
replace({ '__CLIENT__': true, 'process.env.NODE_ENV': JSON.stringify('production') }),
images,
buble({ jsx: 'h', objectAssign: 'Object.assign' }),
!isDev && uglify(uglifyConfig) // uglify slows builds
]
I came across an issue where it says there are issues while using preact-compat on a server side app and it was suggesting to use module-alias as an alternative. So i tried giving the below module-alias in my node server file :-
require('module-alias').addAliases({
'react': 'preact-compat',
'react-dom': 'preact-compat'
})
Even after doing that, i still get the below error :-
Error: Cannot find module 'react'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at r (/my-app/node_modules/react-text-mask/dist/reactTextMask.js:1:145)
at Object.<anonymous> (/my-app/node_modules/react-text-mask/dist/reactTextMask.js: 1:315)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)

Babel JS babel-preset-php error

I was just trying the new Babel's babel-preset-php (https://gitlab.com/kornelski/babel-preset-php#php7-to-es7-syntax-translator). I did everything in the README file, I installed the preset with npm i -S babel-preset-php. Then I created a .babelrc file with the following contents;
{
"presets": ["php"]
}
Installed the cli with npm i -g babel-cli. Then I created a simple PHP file that only contains a simple function:
<?php
function addCalculator($x, $y)
{
return $x + $y;
}
And tried to run the transpiler with babel number.php -o file.js. But I get an error in the execution of the script:
/home/claudio/Documents/Development/babel/node_modules/babel-preset-php/lib/plugins.js:6
Identifier(p) {
^
SyntaxError: Unexpected token ( (While processing preset: "/home/claudio/Documents/Development/babel/node_modules/babel-preset-php/index.js")
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 Object.<anonymous> (/home/claudio/Documents/Development/babel/node_modules/babel-preset-php/index.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I'm not that experient with nodejs and npm, so any idea on what might be happening?
Edit: Ok, I just realized that you are calling a public function outside of a class. That's not correct PHP. You can't define a function as public outside of a class. Your PHP code is just wrong.
The error is being emitted before it even touches your PHP code. It is, in fact, erroring on this particular line of babel-preset-php itself:
return {
visitor: {
Identifier(p) { // This is the invalid line
if (p.node.name != 'Exception' || p.scope.hasBinding("Exception")) {
return;
}
This preset is using the shorthand object initializers added in ECMAScript 2015. What is probably happening here is that your local Javascript environment does not support ES2015 syntax.
I would recommend updating node and babel to the latest versions and trying again.

Node and Require import error in Mocha?

I have a working Node application and I'm trying to add Mocha tests, but getting some odd import errors.
This is my file structure:
package.json
index.js
src/
chart.js
highcharts-options.js
test/
test_chart.js
This is what my chart.js file looks like:
var chartOptions = require('./highcharts-options');
var analyseChart = {
doSomething: function() { ... }
};
module.exports = analyseChart;
And this is what highcharts-options.js looks like:
var HighCharts = require('highcharts-browserify');
Highcharts.theme = { ... };
Currently I import everything from /src into a single index.js file, then bundle it with browserify, which works just fine, no errors in the application.
Now I want to start writing Mocha tests for the functions in /src.
This is my first stub in test_chart.js:
var chart = require('../src/chart');
chart.doSomething();
But when I run mocha, I get the following error:
Users/.../js/src/highcharts-options.js:11
Highcharts.theme = {
^
ReferenceError: Highcharts is not defined
at Object.<anonymous> (/Users/.../js/src/highcharts-options.js:11:1)
at Module._compile (module.js:456:26)
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 Object.<anonymous> (/Users/.../js/src/chart.js:7:20)
at Module._compile (module.js:456:26)
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 Object.<anonymous> (/Users/.../js/test/test_chart.js:1:75)
How can I fix this import error for Mocha?
var HighCharts = require('highcharts-browserify');
Highcharts.theme = { ... };
You have a spelling error.
High[cC]harts
How did you not notice this yourself even when you were told exactly what was wrong?
Some errors are so common that we ultimately stop trusting them, and start looking for other faults in our code without even investigating it.
This is especially true for the "someVar is undefined" error in javascript.
Takeaway:
Sometimes you just got to trust your error messages.

Categories