I am have installed ESlint in out test project and it started to show me few errors that i need to resolve
one of the error is in cy.request('someURL');
The error is cy is undefined
so I have added a import statement on top of file like this
import { cy } from 'cypress';
After adding this statement none of the requests are going through I am getting this error when i try executing the tests.
Tests are executing perfects once i remove the import statement
where am i going wrong
cy is a global variable. Much like location. So really it is window.cy. You can add it to the globals in Eslint. Don't import cy from cypress.
{
"globals": {
"cy": true
}
}
/* global cy */
import above in your test file (cypress test file ex: cypress/integration/login.js
Related
I have 20 autotests and open sypress using comand:
./node_modules/.bin/cypress open
And Cypress window is closed. There is Error in the console:
Error: ENAMETOOLONG: name too long, stat 'cypress/integration/cypress/integration/cypress/integration/cypress/integration/cypress/integration/cypress/integration/cypress/...'
cypress.json:
{
"baseUrl": "https://localhost:3000",
"video": true,
"viewportWidth": 1920,
"viewportHeight": 1024,
"numTestsKeptInMemory": 0,
"defaultCommandTimeout" : 15000,
"testFiles": [
"1_ID.js",
"2_ID.js",
"3_ID.js",
...
"18_ID.js",
"19_ID.js",
"20_ID.js",
]
}
I delete 10 Autotests from the "testFiles" list and Cypress window operate as expected.
What can I do?
You can check for two things in your testFiles array:
Check whether any of the spec file names you added has a typo.
Check whether you have added a file name inside the testFiles array but in reality it doesn't exist.
For me personally I faced the same issue on my windows machine and the reason was point 2.
If you have trouble using testFiles configuration, try using a parent test instead.
my-tests.spec.js
import "1_ID.js";
import "2_ID.js";
import "3_ID.js";
...
import "18_ID.js";
import "19_ID.js";
import "20_ID.js";
Run the parent
npx cypress open --spec "my-tests.spec.js"
This question already has answers here:
Uncaught SyntaxError: Cannot use import statement outside a module
(2 answers)
Closed 2 years ago.
I'm trying to import the PositionalAudioHelper. The code is very basic:
// create the PositionalAudio object (passing in the listener)
import * as THREE from 'three';
var sound = new THREE.PositionalAudio( listener );
var helper = new THREE.PositionalAudioHelper(sound);
sound.add( helper );
The webpack error I get is:
"export 'PositionalAudioHelper' (imported as 'THREE') was not found in 'three'
I installed Three using yarn so it may not install the latest version that includes this commit: https://github.com/mrdoob/three.js/pull/15748
Any ideas on how to do this?
Since PositionalAudioHelper is located on the examples directoy, you have to import it like so:
import { PositionalAudioHelper } from 'three/examples/jsm/helpers/PositionalAudioHelper.js';
three.js R116
I am using graphql-codegen to generate the typescript type files for given schema.
All good except if there is string template in the exported scheme, it will complain the sytax and seems it will not compile it. Check the following files for more details.
The types.js is below:
const gql = require("graphql-tag");
const Colors = ["Red", "Yellow"];
export default gql`
type Person {
name: String
}
enum Color {
${Colors.join("\n")}
}
# if we change the above enum to be the below, it will be good
# enum Color {
# Red
# Yellow
# }
`;
And the config yml file is:
schema:
- types.js
generates:
generated.ts:
plugins:
- typescript
- typescript-resolvers
When run yarn graphql:codegen, it complains the below:
Found 1 error
✖ generated.ts
Failed to load schema from types.js:
Syntax Error: Expected Name, found }
GraphQLError: Syntax Error: Expected Name, found }
at syntaxError (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/error/syntaxError.js:15:10)
at Parser.expectToken (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1404:40)
at Parser.parseName (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:94:22)
at Parser.parseEnumValueDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1014:21)
at Parser.optionalMany (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1497:28)
at Parser.parseEnumValuesDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1002:17)
at Parser.parseEnumTypeDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:986:23)
at Parser.parseTypeSystemDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:705:23)
at Parser.parseDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:146:23)
at Parser.many (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1518:26)
at Parser.parseDocument (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:111:25)
at Object.parse (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:36:17)
at Object.parseGraphQLSDL (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-toolkit/common/index.cjs.js:572:28)
at CodeFileLoader.load (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-toolkit/code-file-loader/index.cjs.js:120:31)
at async /Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-toolkit/core/index.cjs.js:682:25
at async Promise.all (index 0)
GraphQL Code Generator supports:
- ES Modules and CommonJS exports (export as default or named export "schema")
- Introspection JSON File
- URL of GraphQL endpoint
- Multiple files with type definitions (glob expression)
- String in config file
Try to use one of above options and run codegen again.
Error: Failed to load schema
at loadSchema (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-codegen/cli/bin.js:353:15)
Error: Failed to load schema
at loadSchema (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-codegen/cli/bin.js:353:15)
Looks like graphql-codegen didn't like template string like: ${Colors.join('\n')}.
Also please have a look about the repo containing all the above files.
Anyone can help to fix? Thanks.
It's not handling it, mostly because of the complexity of loading code files and interpolate it.
But, the way to workaround is:
Create a single schema.js file.
Import all typedefs with string interpolation from your source files, and use buildSchema (from graphql) or makeExecutableSchema (from graphql-tools) to build a GraphQLSchema object instance.
Export your GraphQLSchema as default export, or as identifier named schema.
Provide that file into codegen (by doing schema: ./schema.js - using a single code file causes the codegen to look for ast code, and then try to do require to it.
If you are using TypeScript, you should also add require extension to the codegen (see https://graphql-code-generator.com/docs/getting-started/require-field#typescript-support)
I tried to run the following script:
import org.apache.commons.io.FileUtils; // necessary import
int lines = FileUtils.readLines(new File("${testPlanFileDir}/csv/test_smtp_save.csv")).size() - 1; // get lines count
vars.put("lines", String.valueOf(lines)); // store the count into "lines" variable
To get the number of lines in my csv, so that I can execute a loop according to the number of lines in the CSV file.
The script above runs perfectly if I run from GUI mode, but when I run from terminal then it throws following error.
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval
Sourced file: inline evaluation of:
``import org.apache.commons.io.FileUtils; // necessary import int lines = FileUtil . . . ''
: Typed variable declaration : Method Invocation FileUtils.readLines
How do you get this ${testPlanFileDir} variable value? Apart from it the code looks good.
If you want to have more relevant error message you can try putting your code into the try block:
import org.apache.commons.io.FileUtils;
try {
int lines = FileUtils.readLines(new File("${testPlanFileDir}/csv/test_smtp_save.csv")).size() - 1;
vars.put("lines", String.valueOf(lines));
}
catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
And look into jmeter.log file - it will contain the "usual" stacktrace.
Alternatively you can add debug() command to the very beginning of your Beanshell script - it will toggle debugging output to stdout
See How to Use BeanShell: JMeter's Favorite Built-in Component for more Beanshell-related tips and tricks
Replace ${testPlanFileDir} by:
vars.get("testPlanFileDir")
You should avoid using Beanshell in favor of JSR223+Groovy+Cache which is embedded in JMeter 3.0, see:
http://jmeter.apache.org/changes.html
https://www.ubik-ingenierie.com/blog/jmeter_performance_tuning_tips/
I used this to get the current directory of .jmx file.
Declared varaible TestPlanFileDir as;
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}
So I am using webpack, babel, and mocha here. When I have code like this:
import userImage from '../../images/user.png';
and I build with webpack, userImage results in a string to the path of the file since I am using the file loader for images (requirements call for me not to embed images) however when I try to run my mocha tests using:
./node_modules/.bin/babel-node ./node_modules/.bin/babel-istanbul cover ./node_modules/.bin/_mocha
I get a syntax error:
SyntaxError: /repositories/react-seed/web/app/images/user.png: Unexpected character '�' (1:0)
> 1 | �PNG
| ^
2 |
3 |
I also get this error when removing istanbul. So it seems like it is trying to load the actually image file however can parse it as JavaScript since it is not.
Anyone know a way around this issue?
You can use the --compilers option which allows you to customize the nodejs require system in order to let it understand png files. So :
mocha --compilers png:./mochacfg.js
Or create a file 'test/mocha.opts' containing (better for your needs):
--compilers png:./mochacfg.js
With ./mochacfg.js:
require.extensions['.png'] = function(){ return null; }
This ignores png files (should be ok if you do nothing special with them).
If you want to do something with the image data:
var fs = require('fs');
require.extensions['.png'] = function(module, filepath) {
var src = fs.readFileSync(filepath).toString ('base64');
return module._compile('module.exports = "data:image/png;base64,' + src + '";');
}
Its quite late to answer this question but just for knowledge sharing purpose, I am answering another approach to do this.
Create a test-config.js file and use it while running the mocha test cases.
var jsdom = require('jsdom').jsdom;
process.env.NODE_ENV = 'test';
// -------------------------------
// Disable webpack-specific features for tests since
// Mocha doesn't know what to do with them.
['.css', '.scss', '.png', '.jpg'].forEach(ext => {
require.extensions[ext] = () => null;
});
and inside package.json use this test command to run the test cases
"test": "mocha ./test/test-setup.js './test/**/*.spec.js' --compilers js:babel-core/register",
I hope it helps someone.