Skip to content

Commit

Permalink
feat: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jubnzv committed Oct 9, 2024
1 parent 74db707 commit d13f839
Show file tree
Hide file tree
Showing 5 changed files with 1,776 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ jobs:

- name: Run ESLint
run: yarn lint

- name: Run tests
run: yarn test
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset : "ts-jest",
testEnvironment : "node",
testPathIgnorePatterns : [ "/node_modules/", "/dist/" ],
maxWorkers : 1,
};

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "tsc",
"test": "jest",
"clean": "rm -rf dist",
"fmt": "prettier --check src",
"lint": "eslint src",
Expand All @@ -35,14 +36,17 @@
"@ton/core": "^0.53.0",
"@ton/crypto": "^3.2.0",
"@ton/ton": "^13.9.0",
"@types/jest": "^29.2.3",
"@types/node": "^20.2.5",
"@typescript-eslint/eslint-plugin": "^7.0.4",
"@typescript-eslint/parser": "^7.0.4",
"cspell": "^8.14.4",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"knip": "^5.30.5",
"prettier": "^3.3.3",
"release-it": "^17.6.0",
"ts-jest": "^29.0.3",
"typescript": "^4.9.5"
},
"peerDependencies": {
Expand Down
57 changes: 57 additions & 0 deletions test/blueprint.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import path from "path";
import fs from "fs";
import { extractProjectInfo, TactProjectInfo } from "../src/blueprint";

describe("extractProjectInfo", () => {
const tempDir = path.join(__dirname, "../wrappers");

beforeAll(() => {
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}
});

afterAll(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});

it('should return project info when lang is "tact"', async () => {
const projectName = "TestContract";
const compileFilePath = path.join(tempDir, `${projectName}.compile.ts`);
const compileFileContent = `
import { CompilerConfig } from '@ton/blueprint';
export const compile: CompilerConfig = {
lang: 'tact',
target: 'contracts/test1.tact',
options: {
debug: true,
},
};
`;
fs.writeFileSync(compileFilePath, compileFileContent);
const result: TactProjectInfo = await extractProjectInfo(compileFilePath);
expect(result).toEqual({
projectName,
target: "contracts/test1.tact",
options: {
debug: true,
},
});
});

it('should throw error when lang is "func"', async () => {
const projectName = "FuncContract";
const compileFilePath = path.join(tempDir, `${projectName}.compile.ts`);
const compileFileContent = `
import { CompilerConfig } from '@ton/blueprint';
export const compile: CompilerConfig = {
lang: 'func',
targets: ['contracts/test2.func'],
};
`;
fs.writeFileSync(compileFilePath, compileFileContent);
await expect(extractProjectInfo(compileFilePath)).rejects.toThrow(
"FunC projects are not currently supported: https://github.com/nowarp/misti/issues/56",
);
});
});
Loading

0 comments on commit d13f839

Please sign in to comment.