Skip to content

Commit

Permalink
Merge pull request #22 from snohio/lastlink/tests
Browse files Browse the repository at this point in the history
yaml interface testing
  • Loading branch information
lastlink authored Mar 25, 2024
2 parents 90bac59 + 3f80217 commit 11e7743
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ _site/
# Local Netlify folder
.netlify
junit.xml
coverage
coverage
*ti.ts
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = {
testMatch: [
"**/tests/**/*.spec.(ts|js)"
],
// turn off console.log
silent: true,
runner: "jest-serial-runner",
testEnvironment: "node",
reporters: ["default", "jest-junit"],
Expand Down
225 changes: 222 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"css": "postcss src/static/css/tailwind.css --o _site/static/css/style.css --watch",
"build": "cross-env NODE_ENV=production eleventy && cross-env NODE_ENV=production postcss src/static/css/tailwind.css --o _site/static/css/style.css",
"browsersync": "browser-sync start --server \"_site\" --files \"_site\" --port 8080 --no-notify --no-open",
"test": "jest -c ./jest.config.js --forceExit --verbose -i --no-cache",
"test:coverage": "jest --forceExit --coverage --verbose",
"test:watch": "jest --watchAll"
"test": "npm run build-interfaces && jest -c ./jest.config.js --forceExit --verbose -i --no-cache",
"test:coverage": "npm run build-interfaces && jest --forceExit --coverage --verbose",
"test:watch": "npm run build-interfaces && jest --watchAll",
"build-interfaces": "npx ts-interface-builder src/**/*interface.ts tests/**/*interface.ts"
},
"devDependencies": {
"@11ty/eleventy": "^2.0.1",
Expand All @@ -34,6 +35,8 @@
"postcss-cli": "^9.1.0",
"prismjs": "^1.26.0",
"tailwindcss": "^3.3.2",
"ts-interface-builder": "^0.3.3",
"ts-interface-checker": "^1.0.2",
"ts-jest": "^29.1.2",
"typescript": "^5.4.3"
},
Expand Down
21 changes: 20 additions & 1 deletion tests/_data/flat_events.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@

const events = require('../../src/_data/flat_events') as any[];

import GroupEventInterfaceTI from "../types/GroupEvent-interface-ti";

import {createCheckers} from "ts-interface-checker";

describe('flat_events', () => {

const { GroupEventFlat } = createCheckers(GroupEventInterfaceTI);
it('should return an array of events', () => {
expect(events).toBeInstanceOf(Array)
expect(events)
.toBeInstanceOf(Array);

});

it('should be of correct type', () => {
for (let i = 0; i < events.length; i++) {
const result = GroupEventFlat.strictValidate(events[i]);
if(result){
expect({index : i, result}).toBeNull();
} else {
expect(result).toBeNull();
}
}
});


Expand Down
23 changes: 23 additions & 0 deletions tests/types/GroupEvent-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface DevEvent {
title: string;
imageUrl: string;
datetime: Date | string;
duration: string;
locationName?: string;
locationUrl?: string;
locationAddress?: string;
description?: string;
tags?: string[];
priceInDollars: number;
}

interface GroupEvent {
host: string;
banner_img?: string;
events?: DevEvent[];
}

interface GroupEventFlat extends DevEvent {
host: string;
bannerImg?: string;
}
Loading

0 comments on commit 11e7743

Please sign in to comment.