Skip to content

Commit

Permalink
Merge pull request #1579 from ecadlabs/mk-1578-ligo-plugin-unit-tests
Browse files Browse the repository at this point in the history
Mk 1578 ligo plugin unit tests
  • Loading branch information
michaelkernaghan authored Dec 12, 2022
2 parents bad0357 + f401de4 commit 8499619
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
6 changes: 5 additions & 1 deletion taqueria-plugin-ligo/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CompileOpts as Opts, emitExternalError, getInputFilename, getLigoDocker

type TableRow = { contract: string; artifact: string };

type ExprKind = 'storage' | 'default_storage' | 'parameter';
export type ExprKind = 'storage' | 'default_storage' | 'parameter';

const COMPILE_ERR_MSG: string = 'Not compiled';

Expand Down Expand Up @@ -287,3 +287,7 @@ const compile = (parsedArgs: Opts): Promise<void> => {
};

export default compile;
export const ___TEST___ = {
getContractNameForExpr,
getOutputExprFilename,
};
14 changes: 9 additions & 5 deletions tests/jest.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
// clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: false,
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
Expand All @@ -28,12 +28,13 @@ export default {
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns: [
'/node_modules/',
'/tests/',
],

// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "v8",
coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
Expand Down Expand Up @@ -126,6 +127,8 @@ export default {
roots: [
'<rootDir>/taqueria-sdk',
'<rootDir>/tests/unit/taqueria-sdk',
'<rootDir>/taqueria-plugin-ligo',
// '<rootDir>/tests/unit/ligo-plugin-tests',
],

// Allows you to use a custom runner instead of Jest's default test runner
Expand Down Expand Up @@ -155,6 +158,7 @@ export default {
// The glob patterns Jest uses to detect test files
testMatch: [
'**/unit/**/?(*.)+(spec).[tj]s?(x)',
'**/unit/**/?(*.)+(spec).mts?(x)',
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/ligo-plugin-tests/ligo-plugin-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ___TEST___, ExprKind } from '../../../taqueria-plugin-ligo/compile';

describe('testing Ligo compile.ts getContractNameForExpr', () => {
const { getContractNameForExpr } = ___TEST___;

test('verify get contract name for storage type', () => {
const exprKind: ExprKind = 'storage';
const sourceFile = 'token.storageList.mligo';
const contractName = getContractNameForExpr(sourceFile, exprKind);
expect(contractName).toBe('token.mligo');
});

test('verify get contract name for default_storage type', () => {
const exprKind: ExprKind = 'default_storage';
const sourceFile = 'token.storageList.mligo';
const contractName = getContractNameForExpr(sourceFile, exprKind);
expect(contractName).toBe('token.mligo');
});

test('verify get contract name for parameter type', () => {
const exprKind: ExprKind = 'parameter';
const sourceFile = 'token.parameterList.mligo';
const contractName = getContractNameForExpr(sourceFile, exprKind);
expect(contractName).toBe('token.mligo');
});

test('verify get contract name fail case', () => {
const { getContractNameForExpr } = ___TEST___;
const sourceFile = 'IAmASourceFile';
try {
const exprKind: ExprKind = 'storage';
const contractName = getContractNameForExpr(sourceFile, exprKind);
expect(contractName).toBe('IAmASourceFile');
} catch (err) {
const error = err as Error;
if (error.message) {
expect(error.message).toContain('Something went wrong internally');
}
}
});
});

0 comments on commit 8499619

Please sign in to comment.