Skip to content

Commit

Permalink
chore: sync template
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 1, 2024
1 parent 205cc73 commit 681b43d
Show file tree
Hide file tree
Showing 17 changed files with 2,867 additions and 800 deletions.
28 changes: 7 additions & 21 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import esbuild from "esbuild";
import * as dotenv from "dotenv";

const typescriptEntries = ["static/scripts/audit-report/audit.ts"];
const cssEntries = ["static/styles/rewards/rewards.css", "static/styles/audit-report/audit.css"];
export const entries = [...typescriptEntries, ...cssEntries];
const typescriptEntries = ["static/main.ts"];
// const cssEntries = ["static/style.css"];
const entries = [
...typescriptEntries,
// ...cssEntries
];

export const esBuildContext: esbuild.BuildOptions = {
sourcemap: true,
Expand All @@ -18,8 +19,7 @@ export const esBuildContext: esbuild.BuildOptions = {
".ttf": "dataurl",
".svg": "dataurl",
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"]),
outdir: "static/dist",
};

esbuild
Expand All @@ -31,17 +31,3 @@ esbuild
console.error(err);
process.exit(1);
});

function createEnvDefines(envVarNames: string[]): Record<string, string> {
const defines: Record<string, string> = {};
dotenv.config();
for (const name of envVarNames) {
const envVar = process.env[name];
if (envVar !== undefined) {
defines[name] = JSON.stringify(envVar);
} else {
throw new Error(`Missing environment variable: ${name}`);
}
}
return defines;
}
11 changes: 11 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents() {
// implement node event listeners here
},
experimentalStudio: true,
baseUrl: "http://localhost:8080",
},
});
12 changes: 12 additions & 0 deletions cypress/e2e/main.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe("Homepage tests", () => {
it("Console is cleared of errors and warnings", () => {
cy.visit("/", {
onBeforeLoad(win) {
cy.stub(win.console, "error").as("consoleError");
},
});
cy.get("@consoleError").should("not.be.called");
cy.get("body").should("exist");
cy.get("h1").should("exist");
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
10 changes: 10 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"roots": ["./tests"],
"coveragePathIgnorePatterns": ["node_modules", "mocks"],
"collectCoverage": true,
"coverageReporters": ["json", "lcov", "text", "clover", "json-summary"],
"reporters": ["default", "jest-junit", "jest-md-dashboard"],
"coverageDirectory": "coverage"
}
29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ts-template",
"version": "1.0.0",
"description": "audit.ubq.fi",
"description": "Template repository with TypeScript support.",
"main": "build/index.ts",
"author": "Ubiquity DAO",
"license": "MIT",
Expand All @@ -15,9 +15,12 @@
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
"format:cspell": "cspell **/*",
"knip": "knip",
"knip-ci": "knip --no-exit-code --reporter json",
"prepare": "husky install"
"knip": "knip --config .github/knip.ts",
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"prepare": "husky install",
"test": "jest --setupFiles dotenv/config --coverage",
"cy:open": "cypress open",
"cy:run": "cypress run"
},
"keywords": [
"typescript",
Expand All @@ -27,35 +30,37 @@
"open-source"
],
"dependencies": {
"@octokit/plugin-throttling": "^8.1.3",
"@octokit/rest": "^20.0.2",
"@sinclair/typebox": "^0.32.14",
"@supabase/supabase-js": "2.39.7",
"axios": "^1.6.7",
"dotenv": "^16.4.4",
"ethers": "^5.7.2",
"godb": "^0.6.2"
"dotenv": "^16.4.4"
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"cspell": "^8.4.0",
"cypress": "13.6.6",
"esbuild": "^0.20.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-filename-rules": "^1.3.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-sonarjs": "^0.24.0",
"husky": "^9.0.11",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"jest-md-dashboard": "0.8.0",
"knip": "^5.0.1",
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"ts-jest": "29.1.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
},
Expand Down
62 changes: 6 additions & 56 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -1,63 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<title>Audit report</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="out/styles/audit-report/audit.css" rel="stylesheet" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ubiquity TypeScript Template</title>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="container">
<h1 class="audit-tag">Audit report</h1>
<!-- params -->
<div class="mb-3">
<label for="repoURLs" class="form-label">Repository URLs</label>
<input type="text" class="form-control" id="repoURLs" />
</div>
<div class="mb-3">
<label for="githubPAT" class="form-label">Github Personal Access Token</label>
<input type="text" class="form-control" id="githubPAT" />
</div>
<div class="mb-3">
<label for="quickName" class="form-label">Quick Import</label>
<textarea
type="text"
class="form-control"
id="quickName"
placeholder='
{
"REPO": "",
"PAT": ""
}'
></textarea>
</div>
<div class="btn-container">
<button type="button" class="btn btn-primary mb-3" id="getReport">
<span class="btn-loader" id="report-loader"></span>
<span>Get report</span>
</button>
</div>
<!-- result table -->
<div class="resultContainer">
<input type="text" id="searchInput" placeholder="Filter Result" />
<table id="resultTable" class="table" style="display: none">
<thead>
<tr>
<th scope="col">Organization/Repo Name</th>
<th scope="col">Issue URL</th>
<th scope="col">Bounty Hunter</th>
<th scope="col" id="amountHeader">Amount <span id="sortArrow">&#8595;</span></th>
<th scope="col">TX URL</th>
</tr>
</thead>
<tbody>
<!-- table content -->
</tbody>
</table>
</div>
</div>
<ul class="notifications"></ul>
<script src="out/scripts/audit-report/audit.js" type="application/javascript"></script>
<h1>Ubiquity TypeScript Template</h1>
<script type="module" src="dist/main.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions static/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export async function mainModule() {
console.log(`Hello from mainModule`);
}

mainModule()
.then(() => {
console.log("mainModule loaded");
Expand Down
12 changes: 12 additions & 0 deletions tests/__mocks__/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// cSpell:disable
import { factory, primaryKey } from "@mswjs/data";

/**
* Creates an object that can be used as a db to persist data within tests
*/
export const db = factory({
users: {
id: primaryKey(Number),
name: String,
},
});
11 changes: 11 additions & 0 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { http, HttpResponse } from "msw";
import { db } from "./db";

/**
* Intercepts the routes and returns a custom payload
*/
export const handlers = [
http.get("https://api.ubiquity.com/users", () => {
return HttpResponse.json(db.users.getAll());
}),
];
4 changes: 4 additions & 0 deletions tests/__mocks__/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { setupServer } from "msw/node";
import { handlers } from "./handlers";

export const server = setupServer(...handlers);
10 changes: 10 additions & 0 deletions tests/__mocks__/users-get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": 1,
"name": "user1"
},
{
"id": 2,
"name": "user2"
}
]
24 changes: 24 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mainModule } from "../static/main";
import { db } from "./__mocks__/db";
import { server } from "./__mocks__/node";
import usersGet from "./__mocks__/users-get.json";
import { expect, describe, beforeAll, beforeEach, afterAll, afterEach, it } from "@jest/globals";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

describe("User tests", () => {
beforeEach(() => {
for (const item of usersGet) {
db.users.create(item);
}
});

it("Should fetch all the users", async () => {
const res = await fetch("https://api.ubiquity.com/users");
const data = await res.json();
expect(data).toMatchObject(usersGet);
expect(async () => await mainModule()).not.toThrow();
});
});
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
Expand Down Expand Up @@ -104,6 +104,7 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"resolveJsonModule": true
}
}
Loading

0 comments on commit 681b43d

Please sign in to comment.