Skip to content

Commit

Permalink
feat: add jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed Apr 14, 2023
1 parent 51f6671 commit c9416cb
Show file tree
Hide file tree
Showing 9 changed files with 14,333 additions and 7,302 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Node.js CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "npm"
- run: npm ci
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
.idea
.swc
19 changes: 19 additions & 0 deletions __tests__/extract-array.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { extractArray } from "../src/utils/chain";

describe("Strings should be extracted from arrays correctly", () => {
it("simple", () => {
const modelResult = `
\`\`\`json
[
"Research and implement natural language processing techniques to improve task creation accuracy.",
"Develop a machine learning model to predict the most relevant tasks for users based on their past activity.",
"Integrate with external tools and services to provide users with additional features such as task prioritization and scheduling."
]
\`\`\`
`;
expect(extractArray(modelResult).length).toBe(3);
expect(extractArray(modelResult).at(2)).toBe(
"Integrate with external tools and services to provide users with additional features such as task prioritization and scheduling."
);
});
});
19 changes: 19 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const nextJest = require("next/jest");

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});

// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ["node_modules", "<rootDir>/"],
testEnvironment: "jest-environment-jsdom",
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);
Loading

0 comments on commit c9416cb

Please sign in to comment.