VueCLI 3 - Eslint Prettier - visual-studio-code

I have issues with this Vue project configuration. I'm using prettier and eslint but files don't get the format the way they should.
I'm using VS Code as code editor and I have prettier installed with formatting on save.
Code Example:
async fetchGenres({ commit }) {
try {
const response = await Vue.axios.get('/api/genres.json/', {
headers: { Authorization: '' }
})
commit('SET_GENRES', response.data)
} catch (err) {
handleRouteError({ err, showReportDialog: false })
}
},
Always gets formatted to this:
async fetchGenres({
commit
}) {
try {
const response = await Vue.axios.get('/api/genres.json/', {
headers: {
Authorization: ''
}
})
commit('SET_GENRES', response.data)
} catch (err) {
handleRouteError({
err,
showReportDialog: false
})
}
},
I've also noticed in case I have semi-colons in the code, they are not removed, at that is not the desired behaviour. Formatting should also get rid of semi-colons.
babel.config.js
module.exports = {
presets: ['#vue/app']
}
.eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
node: true
},
plugins: ['vue', 'prettier'],
extends: ['plugin:vue/essential', '#vue/prettier'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
},
parserOptions: {
parser: 'babel-eslint'
}
}
.prettierrc
{
"printWidth": 160,
"tabWidth": 4,
"singleQuote": true,
"semi": false,
"trailingComma": "none",
"bracketSpacing": true
}
It seems as

Related

Fastify validate schema with yup - schema.validateSync is not a function

From the Fastify documentation in the section titled Using other validation libraries I'm trying to get yup to validate my schema but I keep getting schema.validateSync is not a function and I don't know why??
I want the schema to still be valid for creating the swagger document but I want to use yup to give me the validation I need.
const yup = require("yup");
const yupOptions = {
strict: false,
abortEarly: false,
stripUnknown: true,
recursive: true,
};
async function isUsernameAvailable(fastify: any, _options: Object) {
const users = fastify.mongo.db.collection("users");
fastify.get(
"/api/v1/onboarding/isUsernameAvailable/:username",
{
schema: {
params: {
type: "object",
properties: {
username: { type: "string", maxLength: 12, minLength: 1 },
},
required: ["username"],
},
response: {
200: {
type: "object",
properties: {
available: {
type: "boolean",
description: "Returns true if username is available",
},
},
},
},
},
validatorCompiler: ({ schema, method, url, httpPart }: any) => {
return function (data: any) {
try {
const result = schema.validateSync(data, yupOptions);
return { value: result };
} catch (e) {
return { error: e };
}
};
},
},
async (request: any, _reply: any) => {
const { username } = request.params;
const foundNUsernames = await users.countDocuments(
{ username },
{ limit: 1 }
);
const available: boolean = foundNUsernames === 0;
return { available };
}
);
}
export { isUsernameAvailable };
if I use the below, the validation works but the swagger doc doesn't build
schema: {
params: yup.object({
username: yup.string().lowercase().max(12).min(1).required(),
}),
}
if I remove the validatorCompiler then I get no errors, swagger does build but I cant use yup
validatorCompiler: ({ schema, method, url, httpPart }: any) => {
return function (data: any) {
try {
const result = schema.validateSync(data, yupOptions);
return { value: result };
} catch (e) {
return { error: e };
}
};
},
}
how can I satisfy both?
Why do I want to use yup? I want to validate emails and transform values into lowercase.

can't create cesium ion assets with from parameter

When I create an assets in cesium ion, I can not make it work if I use the from parameter.
this code is working, it create the assets and send back infos about the upload location.
axios.post('https://api.cesium.com/v1/assets', {
name: selectedFile.name,
description: '',
type: '3DTILES',
options: {
position:[ 2.29, 48.85, 0.1],
sourceType: srcType
}
},{
headers: { Authorization: `Bearer ${accessToken}` }
})
.then(response => assetCreated(response))
.catch(function (error) {
console.log(error);
});
But If I add the from parameter like this :
axios.post('https://api.cesium.com/v1/assets', {
name: selectedFile.name,
description: '',
type: '3DTILES',
options: {
position:[ 2.29, 48.85, 0.1],
sourceType: srcType
},
from: {
type:'S3',
bucket: 'mybucket',
credentials :{
accessKey:'key',
secretAccessKey:'secretkey'
}
}
},{
headers: { Authorization: `Bearer ${accessToken}` }
})
.then(response => assetCreated(response))
.catch(function (error) {
console.log(error);
});
Then I get "Request failed with status code 400".
From what I understand from the documentation (https://cesium.com/learn/ion/rest-api/#operation/postAssets) this should work though.
What am I doing wrong ?
Thanks for the help.

Hapi: Error: Cannot set uncompiled validation rules without configuring a validator

Here is my Package.json. I was getting error Hapi: Error: Cannot set uncompiled validation rules without configuring a validator.
"#hapi/boom": "^9.1.0",
"#hapi/hapi": "^19.1.1",
"#hapi/inert": "^6.0.1",
"#hapi/joi": "^17.1.1",
"#hapi/vision": "^6.0.0",
const Hapi = require("#hapi/hapi");
const Joi = require("#hapi/joi")
const server = new Hapi.Server({ host: "localhost", port: 8003 });
server.route({
method: "GET",
path: "/helloWorld",
options: {
validate: {
query: {
name: Joi.string().required()
}
}
},
handler: async (request, h) => {
return 'Hapi'
}
});
server.start();
I have Solve by this:
Here is the reference link:
validate: {
query: >>>>{
name: Joi.string().required()
}<<<
}
},
It should be Joi schema not a plain object.
options: {
validate: {
query:Joi.object({
name:Joi.string().required()
})
}
},

Having test spec name as test name in browserstack

I want to set the test spec name as the test name in browserstack. Below is my browserstack stack config file. I am using protractor.
exports.makeDefaultCapabilities = function(that) {
return {
browserName: 'chrome',
chromeOptions: {
prefs: {
credentials_enable_service: false,
args: [
'disable-infobars=true',
]
},
loggingPrefs: {
driver: 'WARNING',
server: 'WARNING',
browser: 'INFO'
},
'browserstack.user': 'xx'
'browserstack.key': 'xxx',
'browserstack.debug': true,
};
};
exports.config = {
suites: {
smoke: [
'*/*.js'
]
},
SELENIUM_PROMISE_MANAGER: false,
baseUrl: undefined,
framework: 'jasmine',
allScriptsTimeout: 100000,
getPageTimeout: 100000,
maxSessions: 1,
seleniumAddress: 'https://hub-cloud.browserstack.com/wd/hub',
getMultiCapabilities: function() {
let that = this;
return new Promise(function(resolve) {
let defaults = exports.makeDefaultCapabilities(that);
let capabilities = [];
capabilities.push({
os: 'OS X',
os_version: 'High Sierra'
});
_.forEach(capabilities, function(capability) {
_.defaultsDeep(capability, defaults);
});
resolve(capabilities);
});
},
beforeSession: function(config, capabilities, specs) {
capabilities.name = specs && specs[0].split('/').pop() || undefined;
},
onPrepare: function() {
jasmine.getEnv().addReporter(failFast.init());
let reporter = new SpecReporter();
jasmine.getEnv().addReporter(reporter);
}
};
The beforeSession hook doesn't update the test name in browserstack as the test spec name.
Looking forward for any suggestion. Appreciate your help.
Thanks
Include const request = require('request'); in the *.conf.js file and following snippet in onPrepare() function. This will get the name of your test spec and change the name using BrowserStack REST API.
jasmine.getEnv().addReporter({
specStarted: function(result) {
browser.getCapabilities().then(function (capabilities) {
browser.getSession().then(function(session){
var sessionID = session.getId()
var headers = {
'Content-Type': 'application/json'
};
var dataString = `{"name":"${result.fullName}"}`;
var options = {
url: 'https://api.browserstack.com/automate/sessions/' + sessionID + '.json',
method: 'PUT',
headers: headers,
body: dataString,
auth: {
'user': browserstackUser,
'pass': browserstackKey
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
});
});
}
});

Gerkin and Cucumber in Angular 5: Undefined

When I try to create a test using Cucumber and Gherkin I get a strange error. I show you the error first, then the files login.step.ts and login.po.ts:
// Error:
Undefined. Implement with the following snippet:
When('Enter the card number in the box', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
// login.step.ts
import { expect } from 'chai';
const { Given, When, Then, Before } = require('cucumber');
import { browser, by, element } from 'protractor';
import { LoginPage } from './login.po';
let login: LoginPage;
Before(() => {
login = new LoginPage();
});
Given(/^Entering in Login$/, { timeout: 10 * 5000 }, async () => {
await browser.get('http://localhost:49152/login');
});
When(/^Enter the card number in the box$/, () => {
// login.setCardNumber('1234').then((txt) => {
// return 'ready!?';
// })
login.setCardNumber('1234');
});
// login.po.ts
import { browser, by, element, until } from 'protractor';
export class LoginPage {
navigateTo() {
return browser.get('/login');
}
setCardNumber(cardNumber) {
const input = element(by.css('#box'));
return input.sendKeys(cardNumber);
}
}
The first test passes successfully, but in the second test, the process ends in error.
[EDIT]
Adding the protractor.conf.js file:
exports.config = {
allScriptsTimeout: 11000,
specs: [
// './e2e/**/*.e2e-spec.ts',
'./e2e/features/*.feature'
],
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ['disable-infobars']
},
metadata: {
browser: {
name: 'chrome',
version: '58'
},
device: 'Xubuntu Linux',
platform: {
name: 'Linux',
version: '16.04'
}
}
},
directConnect: true,
frameworkPath: require.resolve('protractor-cucumber-framework'),
plugins: [{
package: 'protractor-multiple-cucumber-html-reporter-plugin',
options: {
automaticallyGenerateReport: true,
removeExistingJsonReportFile: true
}
}],
cucumberOpts: {
require: ['./e2e/steps/**/*.ts', './e2e/support/*.ts'],
tags: [],
dryRun: false,
compiler: [],
format: 'json:reports/results.json',
strict: true
},
baseUrl: 'http://localhost:4200/',
SELENIUM_PROMISE_MANAGER: false,
framework: 'custom',
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
}
};
remove the double quote " behind box in /^Enter the card number in the box"$/
I found the answer to my problem. I only had to include the following configuration line to my Before() step in my test:
browser.ignoreSynchronization = true;
According to what I read in different places, it seems that Chrome is looking to perform some task with sockets, and with this line we are disabling this task.