Skip to content

Commit

Permalink
[test] Agrega Prettier y algunas nuevas reglas de eslint
Browse files Browse the repository at this point in the history
Para:
- Cypress
- Nuxt
- Archivos .json
- Detección de claves
  • Loading branch information
andresdameson committed Jul 7, 2020
1 parent 7f22bbb commit 1040b46
Show file tree
Hide file tree
Showing 87 changed files with 3,087 additions and 3,115 deletions.
28 changes: 21 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@ module.exports = {
browser: true,
node: true
},
parser: "vue-eslint-parser",
parserOptions: {
parser: 'babel-eslint'
},
globals: {
$nuxt: true
},
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// https://medium.com/@gogl.alex/how-to-properly-set-up-eslint-with-prettier-for-vue-or-nuxt-in-vscode-e42532099a9c
'plugin:vue/recommended',
'plugin:vue-a11y/recommended',
'plugin:nuxt/recommended',
"plugin:cypress/recommended",
"eslint:recommended",
"prettier/vue",
"plugin:prettier/recommended",
"plugin:json/recommended"
],
plugins: [
// required to lint *.vue files
'vue',
'json',
'vue-a11y',
'nuxt',
'no-secrets',
'cypress',
],
rules: {
"no-secrets/no-secrets": "error",
"vue/component-name-in-template-casing": ["error", "PascalCase"],
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
// https://github.com/maranran/eslint-plugin-vue-a11y/issues/15#issuecomment-507698383
"vue-a11y/label-has-for": [ 2, {
"components": [ "label" ],
"vue-a11y/label-has-for": [2, {
"components": ["label"],
"required": {
"some": [ "nesting", "id" ]
"some": ["nesting", "id"]
},
"allowChildren": false
}]
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ sftp-config.json
sw.*

# Backstop
backstop_data/html_report/
bitmaps_test/
backstop_data/bitmaps_test/*
backstop_data/html_report/*

# Cypress
cypress.env.json
8 changes: 4 additions & 4 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mercadopagoRepository from '~/api/mercadopago'
import mercadopagoRepository from "~/api/mercadopago";

export default $axios => ({
mercadopago: mercadopagoRepository($axios)
})
export default ($axios) => ({
mercadopago: mercadopagoRepository($axios),
});
49 changes: 27 additions & 22 deletions api/mercadopago.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
const resource = 'mercadopago'
const resource = "mercadopago";

export default $axios => ({
async getPaymentMethods({id=null, bin=null}) {
let params = {}
export default ($axios) => ({
async getPaymentMethods({ id = null, bin = null }) {
let params = {};
if (id) {
params.id = id
params.id = id;
}
if (bin) {
params.bin = bin
params.bin = bin;
}
if (!params) {
throw new Exception('No se pudo obtener el método de pago, debe definir algún parámetro de búsqueda.')
throw new Error(
"No se pudo obtener el método de pago, debe definir algún parámetro de búsqueda."
);
}
return $axios.$get(`${resource}/payment-methods`, { params })
return $axios.$get(`${resource}/payment-methods`, { params });
},
async getIdentificationTypes() {
return $axios.$get(`${resource}/get-identification-types`)
return $axios.$get(`${resource}/get-identification-types`);
},
async clearSession() {
return $axios.$get(`${resource}/posts`)
return $axios.$get(`${resource}/posts`);
},
async createToken() {
return $axios.$post(`${resource}/card-tokens/`, {})
return $axios.$post(`${resource}/card-tokens/`, {});
},
async updateToken(id, {
card_number,
security_code,
expiration_month,
expiration_year,
cardholder_name,
cardholder_id_type,
cardholder_id_number,
}) {
async updateToken(
id,
{
card_number,
security_code,
expiration_month,
expiration_year,
cardholder_name,
cardholder_id_type,
cardholder_id_number,
}
) {
return $axios.$put(`${resource}/card-tokens/${id}`, {
card_number,
security_code,
Expand All @@ -40,6 +45,6 @@ export default $axios => ({
cardholder_name,
cardholder_id_type,
cardholder_id_number,
})
});
},
})
});
10 changes: 5 additions & 5 deletions backstop_data/engine_scripts/chromy/clickAndHoverHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module.exports = function (chromy, scenario) {
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector;
const clickSelector = scenario.clickSelectors || scenario.clickSelector;
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector;
const scrollToSelector = scenario.scrollToSelectors || scenario.scrollToSelector;
const keyPressSelector =
scenario.keyPressSelectors || scenario.keyPressSelector;
const scrollToSelector =
scenario.scrollToSelectors || scenario.scrollToSelector;
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]

if (keyPressSelector) {
Expand All @@ -23,9 +25,7 @@ module.exports = function (chromy, scenario) {
}

if (clickSelector) {
chromy
.wait(clickSelector)
.click(clickSelector);
chromy.wait(clickSelector).click(clickSelector);
}

if (postInteractionWait) {
Expand Down
8 changes: 4 additions & 4 deletions backstop_data/engine_scripts/chromy/loadCookies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs');
const fs = require("fs");

module.exports = function (chromy, scenario) {
let cookies = [];
Expand All @@ -10,13 +10,13 @@ module.exports = function (chromy, scenario) {
}

// MUNGE COOKIE DOMAIN FOR CHROMY USAGE
cookies = cookies.map(cookie => {
cookie.url = 'https://' + cookie.domain;
cookies = cookies.map((cookie) => {
cookie.url = "https://" + cookie.domain;
delete cookie.domain;
return cookie;
});

// SET COOKIES VIA CHROMY
chromy.setCookie(cookies);
console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2));
console.log("Cookie state restored with:", JSON.stringify(cookies, null, 2));
};
2 changes: 1 addition & 1 deletion backstop_data/engine_scripts/chromy/onBefore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (chromy, scenario, vp) {
require('./loadCookies')(chromy, scenario);
require("./loadCookies")(chromy, scenario);

// IGNORE ANY CERT WARNINGS
chromy.ignoreCertificateErrors();
Expand Down
4 changes: 2 additions & 2 deletions backstop_data/engine_scripts/chromy/onReady.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (chromy, scenario, vp) {
console.log('SCENARIO > ' + scenario.label);
require('./clickAndHoverHelper')(chromy, scenario);
console.log("SCENARIO > " + scenario.label);
require("./clickAndHoverHelper")(chromy, scenario);
// add more ready handlers here...
};
10 changes: 7 additions & 3 deletions backstop_data/engine_scripts/puppet/clickAndHoverHelper.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
module.exports = async (page, scenario) => {
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector;
const clickSelector = scenario.clickSelectors || scenario.clickSelector;
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector;
const keyPressSelector =
scenario.keyPressSelectors || scenario.keyPressSelector;
const scrollToSelector = scenario.scrollToSelector;
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]

if (keyPressSelector) {
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
await page.waitFor(keyPressSelectorItem.selector);
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
await page.type(
keyPressSelectorItem.selector,
keyPressSelectorItem.keyPress
);
}
}

Expand All @@ -32,7 +36,7 @@ module.exports = async (page, scenario) => {

if (scrollToSelector) {
await page.waitFor(scrollToSelector);
await page.evaluate(scrollToSelector => {
await page.evaluate((scrollToSelector) => {
document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);
}
Expand Down
18 changes: 10 additions & 8 deletions backstop_data/engine_scripts/puppet/ignoreCSP.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*
*/

const fetch = require('node-fetch');
const https = require('https');
const fetch = require("node-fetch");
const https = require("https");
const agent = new https.Agent({
rejectUnauthorized: false
rejectUnauthorized: false,
});

module.exports = async function (page, scenario) {
Expand All @@ -33,33 +33,35 @@ module.exports = async function (page, scenario) {
// FIND TARGET URL REQUEST
if (requestUrl === targetUrl) {
const cookiesList = await page.cookies(requestUrl);
const cookies = cookiesList.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
const cookies = cookiesList
.map((cookie) => `${cookie.name}=${cookie.value}`)
.join("; ");
const headers = Object.assign(request.headers(), { cookie: cookies });
const options = {
headers: headers,
body: request.postData(),
method: request.method(),
follow: 20,
agent
agent,
};

const result = await fetch(requestUrl, options);

const buffer = await result.buffer();
let cleanedHeaders = result.headers._headers || {};
cleanedHeaders['content-security-policy'] = '';
cleanedHeaders["content-security-policy"] = "";
await request.respond({
body: buffer,
headers: cleanedHeaders,
status: result.status
status: result.status,
});
} else {
request.continue();
}
};

await page.setRequestInterception(true);
page.on('request', req => {
page.on("request", (req) => {
intercept(req, scenario.url);
});
};
10 changes: 5 additions & 5 deletions backstop_data/engine_scripts/puppet/interceptImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*
*/

const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");

const IMAGE_URL_RE = /\.gif|\.jpg|\.png/i;
const IMAGE_STUB_URL = path.resolve(__dirname, '../../imageStub.jpg');
const IMAGE_STUB_URL = path.resolve(__dirname, "../../imageStub.jpg");
const IMAGE_DATA_BUFFER = fs.readFileSync(IMAGE_STUB_URL);
const HEADERS_STUB = {};

Expand All @@ -26,12 +26,12 @@ module.exports = async function (page, scenario) {
await request.respond({
body: IMAGE_DATA_BUFFER,
headers: HEADERS_STUB,
status: 200
status: 200,
});
} else {
request.continue();
}
};
await page.setRequestInterception(true);
page.on('request', intercept);
page.on("request", intercept);
};
8 changes: 4 additions & 4 deletions backstop_data/engine_scripts/puppet/loadCookies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs');
const fs = require("fs");

module.exports = async (page, scenario) => {
let cookies = [];
Expand All @@ -10,8 +10,8 @@ module.exports = async (page, scenario) => {
}

// MUNGE COOKIE DOMAIN
cookies = cookies.map(cookie => {
cookie.url = 'https://' + cookie.domain;
cookies = cookies.map((cookie) => {
cookie.url = "https://" + cookie.domain;
delete cookie.domain;
return cookie;
});
Expand All @@ -25,5 +25,5 @@ module.exports = async (page, scenario) => {
);
};
await setCookies();
console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2));
console.log("Cookie state restored with:", JSON.stringify(cookies, null, 2));
};
2 changes: 1 addition & 1 deletion backstop_data/engine_scripts/puppet/onBefore.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = async (page, scenario, vp) => {
await require('./loadCookies')(page, scenario);
await require("./loadCookies")(page, scenario);
};
4 changes: 2 additions & 2 deletions backstop_data/engine_scripts/puppet/onReady.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = async (page, scenario, vp) => {
console.log('SCENARIO > ' + scenario.label);
await require('./clickAndHoverHelper')(page, scenario);
console.log("SCENARIO > " + scenario.label);
await require("./clickAndHoverHelper")(page, scenario);

// add more ready handlers here...
};
6 changes: 3 additions & 3 deletions backstop_data/engine_scripts/puppet/overrideCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module.exports = function (page, scenario) {
// inject arbitrary css to override styles
page.evaluate(`window._styleData = '${BACKSTOP_TEST_CSS_OVERRIDE}'`);
page.evaluate(() => {
const style = document.createElement('style');
style.type = 'text/css';
const style = document.createElement("style");
style.type = "text/css";
const styleNode = document.createTextNode(window._styleData);
style.appendChild(styleNode);
document.head.appendChild(style);
});

console.log('BACKSTOP_TEST_CSS_OVERRIDE injected for: ' + scenario.label);
console.log("BACKSTOP_TEST_CSS_OVERRIDE injected for: " + scenario.label);
};
Loading

0 comments on commit 1040b46

Please sign in to comment.