I get the following error while running the eslint command
PS C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project> eslint "**/*.ts" --ignore-pattern node_modules/
Oops! Something went wrong! :(
ESLint: 8.15.0
TypeError: Cannot read properties of undefined (reading 'property')
Occurred while linting C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\src\tests\rest\Get.test.ts:3
Rule: "codeceptjs/no-actor-in-scenario"
at C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\node_modules\eslint-plugin-codeceptjs\lib\rules\no-actor-in-scenario.js:30:63
at Array.map (<anonymous>)
at C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\node_modules\eslint-plugin-codeceptjs\lib\rules\no-actor-in-scenario.js:29:32
at Array.map (<anonymous>)
at C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\node_modules\eslint-plugin-codeceptjs\lib\rules\no-actor-in-scenario.js:27:34
at Array.map (<anonymous>)
at CallExpression (C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\node_modules\eslint-plugin-codeceptjs\lib\rules\no-actor-in-scenario.js:21:26)
at ruleErrorHandler (C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\node_modules\eslint\lib\linter\linter.js:1114:28)
at C:\WORK\AutomationPlayground\codeceptjs-boilerplate-project\node_modules\eslint\lib\linter\safe-emitter.js:45:58
at Array.forEach (<anonymous>)
This is Get.test.ts file that is causing the error:
Feature('GET tests').tag('#REST')
Scenario('Verify a successful call', async ({ I }) => {
await I.sendGetRequest('/api/users?page=2')
I.seeResponseCodeIsSuccessful()
})
Scenario('Verify a not found call', async ({ I }) => {
await I.sendGetRequest('/api/users/266')
I.seeResponseCodeIsClientError()
})
Scenario('Verify getting a single user', async ({ I }) => {
const { data } = await I.sendGetRequest('/api/users/2')
I.seeResponseContainsKeys(data)
I.seeResponseValidByCallback(({ data, expect }) => {
expect(data.id)
})
})
Scenario('Verify getting list of users', async ({ I }) => {
const { data } = await I.sendGetRequest('/api/users?page=2')
I.seeResponseContainsKeys(data)
I.seeResponseContainsJson({
page: 2,
total: 12,
per_page: 6,
})
})
These are the configuration files for lining:
This is the .eslintrc file:
{
"plugins": [
"codeceptjs"
],
"parserOptions": {
"sourceType": "module"
},
"env": {
"codeceptjs/codeceptjs": true,
"es2020": true
},
"rules": {
"codeceptjs/no-actor-in-scenario": "warn",
"codeceptjs/no-skipped-tests": "error"
}
}
This is my package.json:
"dependencies": {
"#codeceptjs/configure": "^0.8.0",
"#codeceptjs/ui": "0.4.6",
"codeceptjs": "3.3.2",
"codeceptjs-expectwrapper": "^1.0.2",
"codeceptjs-resemblehelper": "^1.9.6",
"expect": "^26.6.2",
"faker": "^4.1.0",
"form-data": "^3.0.0",
"fs-extra": "^10.1.0",
"playwright": "^1.21.0",
"prettier": "2.6.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
},
"devDependencies": {
"eslint": "^8.15.0",
"eslint-plugin-codeceptjs": "^1.3.0"
}
I couldn't find anything on this one.
It seems maybe like some plugin issue. Not really sure.
Can you help resolve the error?
Related
I have a Typescript Mocha setup that I'm using to test my Firestore rules. It uses the latest version of the #firebase/rules-unit-testing library that is part of the Version 9 Firebase SDK.
It also uses the latest Firestore client library that has the newer API that is tree-shakable.
My problem is that Mocha doesn't seem to be able to recognise tests in my nested describe() structure AFTER I call the initializeTestEnvironment() promise.
If you see the output you will see only two tests get executed.
package.json
{
"name": "blocks",
"version": "1.0.0",
"description": "A new Flutter project.",
"main": "index.js",
"private": true,
"scripts": {
"setup": "firebase setup:emulators:firestore",
"test": "firebase emulators:exec --only firestore \"mocha firestore.rules.spec.ts\""
},
"devDependencies": {
"#firebase/rules-unit-testing": "^2.0.2",
"#types/mocha": "^8.2.2",
"firebase-tools": "^10.7.1",
"chai": "^4.3.4",
"mocha": "^9.2.2",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
},
"mocha": {
"recursive": true,
"reporter": "nyan",
"require": "ts-node/register",
"watch-extensions": "ts"
},
"prettier": {
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
}
tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true,
"importHelpers": true,
"module": "commonjs",
"target": "es2019",
"types": [
"node"
]
}
}
firestore.rules.spec.ts
import { before, beforeEach, after } from 'mocha'
import { readFileSync } from 'fs'
import {
assertFails,
assertSucceeds,
initializeTestEnvironment,
} from '#firebase/rules-unit-testing'
import { doc, setDoc, getDoc, updateDoc, deleteDoc } from 'firebase/firestore'
const PROJECT_ID = 'blocks-firestore-rules-testing'
describe('A test that should get run', async () => {
it('should pass', async () => {
return true
})
})
describe('Firestore rules', async () => {
it('should pass also', async () => {
return true
})
const testEnv = await initializeTestEnvironment({
projectId: PROJECT_ID,
firestore: {
rules: readFileSync('firestore.rules', 'utf-8'),
},
})
beforeEach(async () => {
testEnv.cleanup()
await testEnv.clearFirestore()
})
after(async () => {
testEnv.cleanup()
await testEnv.clearFirestore()
})
const uid = 'normal-user'
const user = testEnv.authenticatedContext(uid)
const userRef = doc(user.firestore(), `users/${uid}/`)
const dummyUserDoc = { displayName: 'John Smith' }
it('ensures can create their own user document', async () => {
await assertSucceeds(setDoc(userRef, dummyUserDoc))
})
it('ensures they can read their user document', async () => {
testEnv.withSecurityRulesDisabled(async () => {
setDoc(userRef, dummyUserDoc)
})
await assertSucceeds(getDoc(userRef))
})
it('ensures they can update their user document', async () => {
testEnv.withSecurityRulesDisabled(async () => {
setDoc(userRef, dummyUserDoc)
})
await assertSucceeds(updateDoc(userRef, { foo: 'baz' }))
})
it('ensures cannot delete their user document', async () => {
testEnv.withSecurityRulesDisabled(async () => {
setDoc(userRef, dummyUserDoc)
})
await assertFails(deleteDoc(userRef))
})
})
Command line output:
➜ blocks git:(main) ✗ npm test
> blocks#1.0.0 test
> firebase emulators:exec --only firestore "mocha firestore.rules.spec.ts"
i emulators: Starting emulators: firestore
i firestore: Firestore Emulator logging to firestore-debug.log
i Running script: mocha firestore.rules.spec.ts
2 -_-_,------,
0 -_-_| /\_/\
0 -_-^|__( ^ .^)
-_- "" ""
2 passing (2ms)
✔ Script exited successfully (code 0)
i emulators: Shutting down emulators.
i firestore: Stopping Firestore Emulator
i hub: Stopping emulator hub
I have got an error TS2307: Cannot find module '#jest/globals' or its corresponding type declarations while importing values for my default test suit (but it passes successfully)
import { describe, expect, test } from '#jest/globals'
describe('Example test', () => {
test('something', () => {
expect('').toBeFalsy()
})
})
my package.json
"devDependencies": {
"#types/jest": "^27.0.3",
"#types/node": "^16.11.11",
...
"typescript": "^4.4.4",
},
"optionalDependencies": {
...
},
"dependencies": {
"#jest/globals": "^27.4.2",
"babel-preset-jest": "^27.4.0",
...
}
}
Can anybody helps me?
Firstly I'm using Vuejs and Electron, the package.json will be in the end of this post.
I'm trying to use this listener to show my window as the Electron's documentation recommend.
win.once("ready-to-show", () => win.show());
But it seems that this never fired, only if I manually get the variable win and call the function show().
Below is my background.js (The file that runs the Electron's main process) file and my windowManager.js file (The file that I've created for build my windows and return them, I import this file into background.js)
//background.js
"use strict";
import { app, protocol, BrowserWindow, ipcMain } from "electron";
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
import { windowManager } from "./backend/windowManager.js";
const isDevelopment = process.env.NODE_ENV !== "production";
let winHome, winMain;
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } },
]);
// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", async () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
winHome = await windowManager.createHomeWindow();
winHome.show();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", async () => {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS);
} catch (e) {
console.error("Vue Devtools failed to install:", e.toString());
}
}
winHome = await windowManager.createHomeWindow();
winHome.show();
});
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === "win32") {
process.on("message", (data) => {
if (data === "graceful-exit") {
app.quit();
}
});
} else {
process.on("SIGTERM", () => {
app.quit();
});
}
}
// IPC callback listeners
const closeWindow = () => {
BrowserWindow.getFocusedWindow().close();
};
const openMainWindow = async () => {
winMain = await windowManager.createMainWindow();
winHome.close();
};
// Setting the IPC listeners
ipcMain.on("close-window", closeWindow);
ipcMain.on("open-main-window", openMainWindow);
//windowManager.js
import { BrowserWindow } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import * as path from "path";
export const windowManager = {
async createWindow(sizeProperties, settings, router = null) {
let win;
// Create the browser window.
win = new BrowserWindow({
...sizeProperties,
...settings,
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
preload: path.join(__dirname, "preload.js"),
},
});
//Checking with was sent some router
router = router ? `/#/${router}` : "";
try {
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(`${process.env.WEBPACK_DEV_SERVER_URL}${router}`);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol("app");
// Load the index.html when not in development
await win.loadURL(`app://./index.html${router}`);
}
} catch (error) {
console.error(error);
}
//Setting the default behavior for window
win.once("ready-to-show", () => {
win.show();
});
win.on("closed", () => {
win.destroy();
});
//TODO Check if this line is necessary
win.show();
return win;
},
async createHomeWindow() {
return await this.createWindow(
{
width: 706,
height: 550,
},
{
frame: false, //Remove frame to hide default menu
resizable: false,
show: false, //Don't show at the begin
}
);
},
async createMainWindow() {
let win = await this.createWindow(
{
width: 800,
height: 550,
},
{
frame: false, //Remove frame to hide default menu
show: false, //Don't show at the begin
},
"main"
);
//Extra window behavior
win.maximize();
return win;
},
};
And the package.json
{
"name": "simulans",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.0.3",
"vuex": "^3.4.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-vuex": "~4.5.0",
"#vue/cli-service": "^3.0.5",
"#vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.1.0",
"electron": "^13.0.1",
"electron-devtools-installer": "^3.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^6.2.2",
"prettier": "^2.2.1",
"vue-cli-plugin-electron-builder": "~2.0.0",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"#vue/prettier"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"prettier/prettier": 0
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
You are using an asynchronous function for creating your browser window. This is not a problem, but here, you are binding your BrowserWindow events after you make your asynchonous call.
This basically means that you are waiting for your try/catch block to end before binding your ready-to-show event. I suspect that the event is fired before the asynchronous call ends.
If this is the case, the solution is just to place your win.once("ready-to-show", () => win.show()); before your try { ... } catch ... block.
I have
ArticlesController.js
const Articles = require('../models/Articles');
module.exports = {
list: async(req, res) => {
const articles = await Articles.find({});
console.log(articles);
res.status(200).json({
message: 'Articles'
});
}
};
models/Articles.js
module.exports = {
attributes: {
title: {
type: 'String'
},
body: {
type: 'String'
}
},
datastore: 'mongodb'
};
config/datastores.js
module.exports.datastores = {
mongodb: {
adapter: 'sails-mongo',
url: 'mongodb://localhost:27017/sails-crud'
},
};
package.json
"dependencies": {
"#sailshq/connect-redis": "^3.2.1",
"#sailshq/lodash": "^3.10.3",
"#sailshq/socket.io-redis": "^5.2.0",
"grunt": "1.0.4",
"mongodb": "^2.2.25",
"sails": "^1.4.2",
"sails-hook-grunt": "^4.0.0",
"sails-hook-orm": "^3.0.2",
"sails-hook-sockets": "^2.0.0",
"sails-mongo": "^1.2.0"
}
But this is the error I get
error: Sending 500 ("Server Error") response: TypeError:
Articles.find is not a function
I have tried using find.exec as well, same error with that as well.
Help me resolve it.
I added couple of lines to check for errors on my REST API(POST method).
Lines 39-60
app.post('/collections/:collectionName', (req, res, next) => {
pino(req,res);
req.log.info('pino output');
try {
req.collection.insert(req.body, {}, (e, results) => {
if (e) return next(e)
res.send(results.ops)
} catch (err) {
if (err instanceof CustomError) {
return res.status(err.status).send({
error: err.code,
description: err.message,
}) else {
console.error(err);
return res.status(500).send({
error: 'GENERIC',
description: 'Something went wrong!!!',
})
}
}
}
})
When I run
eslint --fix index.js
/home/miki/restwitherrors/index.js
46:7 error Parsing error: Unexpected token catch
✖ 1 problem (1 error, 0 warnings)
If I try in VSCode,Shift+ALt+. and choose Fix all detected spelling errors
output is
<semantic> TypeScript Server Error (3.8.3)
Cannot read property 'groups' of null
TypeError: Cannot read property 'groups' of null
at DiagnosticIDDecorator.UndecorateFix (/home/miki/.vscode/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Diagnostics/DiagnosticIDDecorator.js:65:92)
at DiagnosticIDDecorator.UndecorateCombinedFix (/home/miki/.vscode
/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Diagnostics/DiagnosticIDDecorator.js:75:109)
at /home/miki/.vscode/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Plugin.js:397:45
at Proxy.<anonymous> (/home/miki/.vscode/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Interception/Interceptor.js:100:34)
at IOSession.Session.getCombinedCodeFix (tsserver.js:145760:56)
at Session.handlers.ts.createMapFromTemplate._a.<computed> (tsserver.js:144516:61)
at tsserver.js:146003:88
at IOSession.Session.executeWithRequestId (tsserver.js:145994:28)
at IOSession.Session.executeCommand (tsserver.js:146003:33)
at IOSession.Session.onMessage (tsserver.js:146027:35)
at Interface.<anonymous> (tsserver.js:147342:27)
at Interface.emit (events.js:203:13)
at Interface._onLine (readline.js:316:10)
at Interface._normalWrite (readline.js:461:12)
at Socket.ondata (readline.js:172:10)
at Socket.emit (events.js:203:13)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:276:11)
at Socket.Readable.push (_stream_readable.js:210:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
How to get more info? How to fix syntax automatically?
I am adding my .eslinter.json
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"plugin:react/recommended",
"standard"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
}
}
I think that you should close your function insert before that you open your catch