Skip to content

Instantly share code, notes, and snippets.

Avatar
🏁
Racing through work

Robert DeLuca Robdel12

🏁
Racing through work
View GitHub Profile
View snapshots.js
const PercyScript = require('@percy/script');
const fs = require('fs');
const path = require('path');
const directories = [
path.resolve(__dirname, '../src/components/elements'),
path.resolve(__dirname, '../src/components/patterns'),
path.resolve(__dirname, '../src/components/templates'),
];
View snapshots.js
const PercyScript = require("@percy/script");
const fs = require("fs");
const path = require("path");
const directories = [
{
type: "Element",
path: path.resolve(__dirname, "src/components/elements")
},
{
View config.yaml
events:
enabled: true
subscriptions:
- command: node ~/scripts/turn-off-printer.js
event: PrintDone
type: system
system:
actions:
- name: Turn off printer
action: turnoff
@Robdel12
Robdel12 / toggle-plug.js
Last active Jul 22, 2021
Toggle Meross Plug from Node
View toggle-plug.js
"use strict";
// TODO: I know, I know, don't use request...
const request = require("request");
// Wrap request with a promise to make it awaitable
function doRequest(options) {
return new Promise(function(resolve, reject) {
request(options, function(error, res, body) {
if (!error && res.statusCode == 200) {
View bitbucket-pipelines.yml
pipelines:
default:
- step:
name: Visual test
image: circleci/node:8-browsers
script:
- node -v
- npm -v
- npx percy exec -- node ./snapshots.js
View package.json
{
"devDependecies": {
},
"percy": {
"version": 1,
"agent": {
"request-headers": {
"Authentication": "Basic c3RnOnN0ZzEyMw=="
}
@Robdel12
Robdel12 / cypress-interactor.js
Created Jul 15, 2019
Interactor.js + Cypress
View cypress-interactor.js
beforeEach(function() {
// Tell Interactor where the applications DOM is
// since Cypress runs the test specs in an isolated iframe (away from the app DOM)
cy.window().then(remoteWindow => {
Object.defineProperty(Interactor.prototype, "$dom", {
get() {
return remoteWindow;
}
});
});
View get-example-dom.js
export default function getExampleDOM() {
// This is just a raw example of setting up some DOM
// that we can interact with. Swap this with your UI
// framework of choice 😉
let div = document.createElement("div");
div.innerHTML = `
<label for="username">Username</label>
<input id="username" />
<button>Print Username</button>
View myinput.test.js
import { mount } from 'testing-hooks/react-dom';
import { type } from 'interactor.js';
import MyInputComponent from './MyInputComponent';
describe('MyInputComponent', () => {
beforeEach(async () => {
await mount(
<MyInputComponent {...props} />
);
});
@Robdel12
Robdel12 / lambda.js
Created May 2, 2019 — forked from luketheobscure/lambda.js
Percy Bitbucket AWS Lambda
View lambda.js
const https = require('https');
const AUTHORIZATION = ''; // base 64 of user:password
const BITBUCKET_USER = ''; // either the user or the org that owns the repo
const PERCY_USER = ''; // the name of your percy user or org
exports.handler = (event, context, callback) => {
/**
We need to post to a URL like this:
https://api.bitbucket.org/2.0/repositories/<user>/<repo>/commit/<hash>/statuses/build