/// <reference types= "cypress" /> not enabling intellisense in VS code - intellisense

I'm having a problem trying to get code completion for Cypress while I'm using JS. I've tried following every bit of documentation I could found, but I don't find these comprehensive enough.

None of these worked for me, what finally gave me Intellisense was adding a tsconfig.json file to the Cypress folder, as per the Cypress docs:
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../node_modules",
"types": ["cypress"]
},
"include": ["**/*.*"]
}

I just added
"compilerOptions": {
"types": ["cypress"]
}
to the object in the tsconfig.json file that was in the root cypress directory. I then chose "Restart TS Server" from the Command Palette and that sorted things out for me.

This is because you installed Cypress via the .exe, which is not the recommended way of installing Cypress.
Cypress type definitions are only installed when you install cypress via npm
For VSCode to find the type definitions,
you should install cypress as a dev dependency to your project (preferred form of installation according to the docs):
npm i -D cypress

Hi I was able to set it on vs code by simple adding ///
I've written it previously with C from Cyberpress in lower case, after adding the C in upper case it solved my problem

How I get Cypress typings to work in vscode
I had problems getting Cypress intellisense to work too. My way to get intellisense is convoluted and probably wrong, but I didn't get it to work in any other way.
add a cypress.d.ts file in the root of my project with the following types syntax. This declare the cy type, so you get autocompletion for most Cypress stuff:
declare var Cypress: any;
interface CypressElement {
type(value: string, options?: any): CypressElement,
clear(options?: {force: boolean}): CypressElement,
click(options?: {force: boolean}): CypressElement,
should(...args: any): CypressElement,
selectValue(option: number, optionsClass: string):CypressElement,
fillInput(value: string):CypressElement,
eq(index: number): CypressElement,
contains(value: any): CypressElement,
within(...args: any): any,
trigger(...args: any): any;
first(): CypressElement;
}
declare var cy: {
get(select: any): CypressElement;
window(): Promise<any>;
visit(path: any): void;
request(options: any): Promise<any>;
wait(time: string | number): any;
server(): any;
route(...options: any): any;
log(...messages: string[]): any;
contains(selector: string, value: any): any;
stub(...args: any): any;
on(event: string, callback: any): any;
url(): CypressElement;
};
(Declare Cypress typings manually this way seems alien at best. However, trying to use the native ones generated a lot of problems)
Reference that file in the tsconf.json compiler options via:
"typeRoots": ["cypress.d.ts"],
This just enables intellisense to Cypress, even if the cypress code is written in javaScript, since vscode relies a lot in typescript for its intellisense engine.
Since you're not using typeScript I guess, you may need to add a very simple tsconfig file at the root (so your editor can read its configuration), something like:
{
"compilerOptions": {
"typeRoots": ["cypress.d.ts"],
"target": "es5",
"module": "commonjs",
"lib": [
"es6"
],
"declaration": true,
"removeComments": false,
"stripInternal": true,
// since 2.3
// "strict": true,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true
},
"files": [
"./index.ts"
]
}
Maybe you can instruct your editor to load cypress.d.ts as typeRoots, I don't know.
After this, you should have intellisense for your cy variable and for the objets that comes from cy.get() (which above are called CypressElement in that types definition).
One big caveat about this, is that whenever you use a new Cypress feature, you need to manually add its type to cypress.d.ts to get the intellisense.

Related

What is the default CSS property order?

i have been trying to find documentation on this but i havent been able to. I use stylint in a project and we have the css order option activated. I haven't been able to set up VS code to show the errors and i haven't found a page with the information to actually know the order,so i always need to check on compile time if i have any mistakes in the CSS order properties, and it shows a huge error on screen.
this are the stylelint rules we have
module.exports = {
extends: ['stylelint-config-standard', 'stylelint-config-concentric-order'],
rules: {
'at-rule-no-unknown': [
true,
{
ignoreAtRules: ['mixin', 'if', 'else', 'include', 'extend']
}
],
'max-nesting-depth': 4,
indentation: 4,
// add your custom config here
// https://stylelint.io/user-guide/configuration
'selector-pseudo-element-no-unknown': [
true,
{
ignorePseudoElements: ['v-deep']
}
]
}
}
I dont see anything weird about it. It there a page where i can find the correct order? it is so annoying because when i get a stylelint order error, i usually have to find it in a few tries.
You are extending the stylelint-config-concentric-order community config. This config includes and configures the stylelint-order community plugin. You can find the order of the properties in the repo on GitHub.
You can see Stylelint errors in VS Code using the official Stylelint extension.
And you can have the extension automatically fix problems on save, which will include the order of your properties, using the editor.codeActionsOnSave configuration property:
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
},
"stylelint.validate": ["css", "postcss","scss"],
"css.validate": false,
"scss.validate": false
}
Alternatively, you can run npx stylelint "**/*.scss" --fix" on the command line to automatically fix problems.

Less.js setting file property to 'to.css' in sourcemap

so using lessc(2.7.2) compiler and the the following
less.render(data, {
filename: entryFile,
plugins: [autoprefixPlugin],
compress: true,
sourceMap: {
sourceMapURL: '/static/extensions/css/index.css.map',
sourceMapBasepath: 'project/web/webroot/',
sourceMapRootpath: '/',
outputSourceFiles: true,
sourceMapFullFilename: '/static/extensions/css/index.css'
}
})
It generates a CSS/map string which are then written to files. now I've worked out most of the setting, but I'm still getting one issue.
In the .map file, the property "file" is set to "to.css".
I understand why, the compiler does not know the name of the file as it's not written yet, but I can't find anything in the docs about this either.
Am I missing an option?

eslint erroring on es6 when .js files, fine for .jsx files

error: Parsing error: Unexpected token ..
My lint gulp task is giving me issues on '.js' files, while '.jsx' are doing fine on ES6 syntax.
Notably, the "..." operator - for spread/rest etc.
Is there a way to get this to work? Here is part of my config. (I tried adding ".js: true", didn't help)
{
"parser":"espree",
"ecmaFeatures":{
"modules":true,
"jsx":true
},
You probably want to enable the experimentalObjectRestSpread parser option:
{
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true,
"modules": true
}
}
Since Espree is already the default parser, you don't need to specify it unless you want to for clarity's sake.

TypeScript bundling not working for External Modules

I've a sample TypeScript code and I'm trying to bundle multiple ts/tsx files using typescript compiler (tsc).
Here is the code:
File: ISample.ts
class ISample{
constructor(public value:string){
}
}
export = ISample;
File: Sample.ts
import ISample = require('./ISample');
class SampleImpl{
value: ISample;
constructor(sample:number){
this.value = new ISample(sample+'');
}
}
File: tsconfig.json
{
"compilerOptions": {
"module": "amd",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"jsx": "react",
"outFile": "./dist/bundle.js",
"target": "es3",
"listFiles": true,
"sourceMap": false
},
"files": [
"./src/Sample.ts",
"./src/ISample.ts"
]
}
When I run the command:
tsc
bundle.js is generated but it is completely blank.
Observations:
The problem doesn't occur when I move the code to Internal Modules
The problem also doesn't occur when I omit the import/require statement and use a declaration for ISample class, but in that case bundle.js does not contain the code of ISample class
Any ideas why this is happening?
This is not supported for now: Suggestion: multi-file external modules.
There are a set of workarounds, e.g. Compile TypeScript with modules and bundle to one file

Wallaby with Browserify and TypeScript modules

I am trying to get Wallaby to work with a TypeScript app, using Browserify and Wallabify. However, when I run Wallaby, it outputs No failing tests, 0 passing, and all test indicators are grey.
The file app/spec.setup.ts is responsible for loading node modules dependencies such as chai, sinon, and the app's main module. app/spec.util.ts provides some helpers, imported by individual spec files.
module.exports = function() {
var wallabify = require('wallabify');
var wallabyPostprocessor = wallabify({
entryPatterns: [
'app/spec.setup.ts',
'app/src/**/*.spec.ts'
]
}
);
return {
files: [
{pattern: 'app/spec.setup.ts', load: false, instrument: false},
{pattern: 'app/spec.util.ts', load: false, instrument: false},
{pattern: 'app/src/**/*.ts', load: false},
{pattern: 'app/src/**/*.spec.ts', ignore: true}
],
tests: [
{pattern: 'app/src/**/*.spec.ts', load: false}
],
testFramework: 'mocha',
postprocessor: wallabyPostprocessor,
bootstrap: function (w) {
// outputs test file names, with .ts extensions changed to .js
console.log(w.tests);
window.__moduleBundler.loadTests();
}
};
};
What's interesting is that I don't get any feedback from changing entryPatterns, even setting it to an empty array or invalid file names. The result is still the same. Only if I remove it entirely, I get errors such as Can't find variable: sinon.
I've also figured that the entryPatterns list may need the compiled file names, i.e. .js instead of .ts extension. However, when I do that, I get Postprocessor run failure: 'import' and 'export' may appear only with 'sourceType: module' on spec.setup.ts.
I don't know what is the correct way to configure Wallabify for TypeScript compilation, and I couldn't find any complete examples on the web, so I'd appreciate any hints.
P.S. with my current StackOverflow reputation I couldn't add two new tags: wallaby and wallabify. Could someone do me a favour and add the two tags please.
Because TypeScript compiler renames files to .js and applied before wallabify, you need to change your entry patterns like this to make it work:
entryPatterns: [
'app/spec.setup.js',
'app/src/**/*.spec.js'
]