Skip to content

Commit

Permalink
test: ✅ Attempt at approval testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 23, 2021
1 parent 60d18cd commit 30e5bfa
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ package-lock.json

# obsidian
data.json

# Tests

*.received.*
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup -c --environment BUILD:production",
"release": "standard-version"
"release": "standard-version",
"test": "ts-mocha"
},
"standard-version": {
"t": ""
Expand All @@ -19,19 +20,24 @@
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/csv2json": "^1.4.2",
"@types/expect": "^24.3.0",
"@types/lodash": "^4.14.171",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"approvals": "^4.0.0-beta.1",
"auto-plugin-obsidian": "^0.1.4",
"eslint": "^7.29.0",
"mocha": "^9.1.3",
"obsidian": "^0.12.0",
"obsidian-dataview": "^0.4.20",
"rollup": "^2.32.1",
"rollup-plugin-svelte": "7.1.0",
"standard-version": "^9.3.1",
"svelte-check": "1.1.14",
"svelte-preprocess": "4.7.3",
"ts-mocha": "^8.0.0",
"tslib": "^2.2.0",
"typescript": "^4.4.2"
},
Expand All @@ -51,4 +57,4 @@
"svelte": "3.35.0",
"svelte-icons": "^2.1.0"
}
}
}
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ export default {
include: "node_modules/**",
}),
],
};
};
6 changes: 6 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import _ from "lodash";
import Graph from "graphology";

export function myFunc(str: string) {
return new Graph();
}
68 changes: 68 additions & 0 deletions src/typings/approvals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
declare module "approvals" {
export type ApprovalsOptions = any;

export interface MochaInstance {
verify(data: any, overrideOptions: Partial<ApprovalsOptions>): void;
}

export function configure(overrideOptions: Partial<ApprovalsOptions>): void;

export function getConfig(
overrideOptions: Partial<ApprovalsOptions>
): ApprovalsOptions;

export function verify(
dirName: string,
testName: string,
data: string | Buffer,
optionsOverride: Partial<ApprovalsOptions>
): void;

export function verifyAndScrub(
dirName: string,
testName: string,
data: string | Buffer,
scrubber: (file: string) => string,
optionsOverride: Partial<ApprovalsOptions>
): void;

export function verifyAsJSON(
dirName: string,
testName: string,
data: any,
optionsOverride: Partial<ApprovalsOptions>
): void;

export function verifyAsJSONAndScrub(
dirName: string,
testName: string,
data: any,
scrubber: (file: string) => string,
optionsOverride: Partial<ApprovalsOptions>
): void;

export function verifyWithControl(
namer: string,
writer: string,
reporterFactory: string,
optionsOverride: Partial<ApprovalsOptions>
): void;

export const reporters: {
MultiReporter: any;
};

export namespace scrubbers {
export function noScrubber(): void;

export function guidScrubber(): void;

export function multiScrubber(): void;
}

/**
* Configure approvals to hook into Mocha tests.
* @param {*} optionalBaseDir - An optional folder to save approval files to.
*/
export const mocha: (optionalBaseDir?: string) => void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
15 changes: 15 additions & 0 deletions test/approvals1.1.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { mocha } from "approvals";
import type { ITestCallbackContext } from "mocha";
import { getReflexiveClosure } from "../src/sharedFunctions";
import Graph from "graphology";

describe("typescript simple Approvals tests #1.1", () => {
mocha(__dirname);

it("tutu", function (this: ITestCallbackContext) {
const g = new Graph()
const value = getReflexiveClosure(g, []);

this.verify(value);
});
});
6 changes: 6 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--require ts-node/register
--require source-map-support/register
--recursive
--full-trace
--bail
test/**/*.spec.ts
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
import { MultiGraph } from "graphology";
// import { getReflexiveClosure } from "src/sharedFunctions";
exports.__esModule = true;
require("approvals").mocha();
describe("When running some tests", function () {
it("should be able to use Approvals", function () {
var data = "test";
// const userHiers = [
// {
// down: ["down"],
// next: ["next"],
// prev: ["prev"],
// same: ["same"],
// up: ["up"],
// },
// ];
// const g = new MultiGraph();
// g.addNode("A");
// g.addNode("B");
// g.addNode("C");
// g.addEdge("A", "B", { dir: "up", field: "parent" });
// g.addEdge("C", "A", { dir: "prev", field: "previous" });
// getReflexiveClosure(g, userHiers);
this.verify(data); // or this.verifyAsJSON(data)
});
});
33 changes: 33 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// import { MultiGraph } from "graphology";
// import { getReflexiveClosure } from "src/sharedFunctions";

require("approvals").mocha();

describe("When running some tests", function () {
it("should be able to use Approvals", function () {
const data = "test";
// const userHiers = [
// {
// down: ["down"],
// next: ["next"],
// prev: ["prev"],
// same: ["same"],
// up: ["up"],
// },
// ];

// const g = new MultiGraph();
// g.addNode("A");
// g.addNode("B");
// g.addNode("C");

// g.addEdge("A", "B", { dir: "up", field: "parent" });
// g.addEdge("C", "A", { dir: "prev", field: "previous" });

// getReflexiveClosure(g, userHiers);

this.verify(data); // or this.verifyAsJSON(data)
});
});

export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TUTU
11 changes: 9 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",

"include": ["src/**/*", "src/*", "**/*.ts"],
"include": [
"src/**/*",
"src/*",
"**/*.ts",
"test/test.js",
"test/**/*.ts",
"typings/**/*.ts"
],
"exclude": ["node_modules/*"],
"compilerOptions": {
"types": ["node", "svelte"],
"types": ["node", "svelte", "mocha"],
"baseUrl": ".",
"paths": {
"src": ["src/*"]
Expand Down

0 comments on commit 30e5bfa

Please sign in to comment.