Skip to content

Commit

Permalink
Added e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sinapsist committed Sep 20, 2022
1 parent 8cb6fcd commit c22e6d0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 21 deletions.
7 changes: 3 additions & 4 deletions tests/e2e/data/hello-tacos-tests.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let test_available_tacos =
assert (Test.get_storage taddr = available_tacos)

let test_buy_tacos =
let (taddr, _, _) = Test.originate main available_tacos 100tez in
let contr = Test.to_contract taddr in
let _ = Test.transfer_to_contract_exn contr 1n in
assert (Test.get_storage taddr = 100n)
let res = main(1n, available_tacos) in (* The nature of the contract we don't have entrypoints
// The only way to test it is to call function itself *)
assert (res.1 = 99n)
34 changes: 17 additions & 17 deletions tests/e2e/taqueria-plugin-ligo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('E2E Testing for taqueria ligo plugin', () => {
} catch (_) {}
});

test.skip('Verify that the ligo plugin exposes the associated commands in the help menu', async () => {
test('Verify that the ligo plugin exposes the associated commands in the help menu', async () => {
try {
const ligoHelpContents = await exec(`taq --help --projectDir=${taqueriaProjectPath}`);
expect(ligoHelpContents.stdout).toBe(contents.helpContentsLigoPlugin);
Expand All @@ -28,7 +28,7 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

test.skip('Verify that the ligo plugin exposes the associated options in the help menu', async () => {
test('Verify that the ligo plugin exposes the associated options in the help menu', async () => {
try {
const ligoHelpContents = await exec(`taq compile --help --projectDir=${taqueriaProjectPath}`);
expect(ligoHelpContents.stdout).toBe(contents.helpContentsLigoPluginSpecific);
Expand All @@ -37,7 +37,7 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

test.skip('Verify that the ligo plugin aliases expose the correct info in the help menu', async () => {
test('Verify that the ligo plugin aliases expose the correct info in the help menu', async () => {
try {
const ligoAliasCHelpContents = await exec(`taq c --help --projectDir=${taqueriaProjectPath}`);
expect(ligoAliasCHelpContents.stdout).toBe(contents.helpContentsLigoPluginSpecific);
Expand All @@ -51,15 +51,15 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

test.skip('Verify that taqueria ligo plugin outputs no contracts message if no contracts exist', async () => {
test('Verify that taqueria ligo plugin outputs no contracts message if no contracts exist', async () => {
try {
await exec(`taq compile`, { cwd: `./${taqueriaProjectPath}` });
} catch (error) {
expect(String(error)).toContain(contents.ligoNoContractSource);
}
});

test.skip('Verify that taqueria ligo plugin throw an error message if contract name is not specified', async () => {
test('Verify that taqueria ligo plugin throw an error message if contract name is not specified', async () => {
try {
// 1. Copy contract from data folder to taqueria project folder
await exec(`cp e2e/data/hello-tacos.mligo ${taqueriaProjectPath}/contracts`);
Expand All @@ -75,7 +75,7 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

test.skip('Verify that taqueria ligo plugin can compile one contract using compile [sourceFile] command', async () => {
test('Verify that taqueria ligo plugin can compile one contract using compile [sourceFile] command', async () => {
try {
// 1. Copy contract from data folder to taqueria project folder
await exec(`cp e2e/data/hello-tacos.mligo ${taqueriaProjectPath}/contracts`);
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

test.skip('Verify that taqueria ligo plugin will display proper message if user tries to compile contract that does not exist', async () => {
test('Verify that taqueria ligo plugin will display proper message if user tries to compile contract that does not exist', async () => {
try {
// 1. Run taq compile ${contractName} for contract that does not exist
const { stdout, stderr } = await exec(`taq compile test.mligo`, { cwd: `./${taqueriaProjectPath}` });
Expand All @@ -129,7 +129,7 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

test.skip('Verify that taqueria ligo plugin emits error and yet displays table if contract is invalid', async () => {
test('Verify that taqueria ligo plugin emits error and yet displays table if contract is invalid', async () => {
try {
await exec(`cp e2e/data/invalid-contract.mligo ${taqueriaProjectPath}/contracts`);
await exec(`taq add-contract invalid-contract.mligo`, { cwd: `./${taqueriaProjectPath}` });
Expand All @@ -143,41 +143,41 @@ describe('E2E Testing for taqueria ligo plugin', () => {
}
});

// TODO:
test('Verify that taqueria ligo plugin can run ligo test using taq test <sourceFile> command', async () => {
try {
// 1. Copy contract and tests files from data folder to taqueria project folder
await exec(`cp e2e/data/hello-tacos.mligo ${taqueriaProjectPath}/contracts`);
await exec(`cp e2e/data/hello-tacos-tests.mligo ${taqueriaProjectPath}/contracts`);

// 2. Run taq test ${testFileName}
const { stdout, stderr } = await exec(`taq test hello-tacos-tests.mligo`, { cwd: `./${taqueriaProjectPath}` });
console.log(stdout);
expect(stdout).toContain('All tests passed');
} catch (error) {
throw new Error(`error: ${error}`);
}
});

// TODO:
test('Verify that taqueria ligo plugin will output proper error message running taq test <sourceFile> command against invalid test file', async () => {
try {
// 1. Copy contract and tests files from data folder to taqueria project folder
await exec(`cp e2e/data/hello-tacos--invalid-tests.mligo ${taqueriaProjectPath}/contracts`);
await exec(`cp e2e/data/hello-tacos-invalid-tests.mligo ${taqueriaProjectPath}/contracts`);

// 2. Run taq test ${testFileName}
// const output = await exec(`taq test hello-tacos-invalid-tests.mligo`, { cwd: `./${taqueriaProjectPath}` });
console.log(await exec(`taq test hello-tacos-invalid-tests.mligo`, { cwd: `./${taqueriaProjectPath}` }));
const { stdout, stderr } = await exec(`taq test hello-tacos-invalid-tests.mligo`, {
cwd: `./${taqueriaProjectPath}`,
});
expect(stdout).toContain('Some tests failed :(');
expect(stderr).toContain('Variable "initial_storage" not found.');
} catch (error) {
throw new Error(`error: ${error}`);
}
});

// TODO:
test('Verify that taqueria ligo plugin will output proper error message running taq test <sourceFile> command against non-existing file', async () => {
try {
// 1. Run taq test ${testFileName} against file that does not exist
const { stdout, stderr } = await exec(`taq test hello-tacos-tests.mligo`, { cwd: `./${taqueriaProjectPath}` });
console.log(stderr);
const { stdout, stderr } = await exec(`taq test hello-tacos-test.mligo`, { cwd: `./${taqueriaProjectPath}` });
expect(stderr).toContain('contracts/hello-tacos-test.mligo: No such file or directory');
} catch (error) {
throw new Error(`error: ${error}`);
}
Expand Down
68 changes: 68 additions & 0 deletions tests/e2e/taqueria-plugin-multiple-test-plugins.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { exec as exec1 } from 'child_process';
import { createHash } from 'crypto';
import fsPromises from 'fs/promises';
import path from 'path';
import util from 'util';
import * as contents from './data/help-contents/ligo-contents';
import { checkFolderExistsWithTimeout, generateTestProject } from './utils/utils';
const exec = util.promisify(exec1);

const taqueriaProjectPath = 'e2e/auto-test-multi-test-plugins';

describe('E2E Testing for taqueria ligo plugin', () => {
beforeAll(async () => {
await generateTestProject(taqueriaProjectPath, ['ligo', 'jest']);
// TODO: This can removed after this is resolved:
// https://github.com/ecadlabs/taqueria/issues/528
try {
await exec(`taq -p ${taqueriaProjectPath}`);
} catch (_) {}
});

test('Verify that --plugin required to', async () => {
try {
// 1. Copy contract and tests files from data folder to taqueria project folder
await exec(`cp e2e/data/hello-tacos.mligo ${taqueriaProjectPath}/contracts`);
await exec(`cp e2e/data/hello-tacos-tests.mligo ${taqueriaProjectPath}/contracts`);

// 2. Run taq test ${testFileName}
await exec(`taq test hello-tacos-tests.mligo`, { cwd: `./${taqueriaProjectPath}` });
} catch (error) {
expect(String(error)).toContain('Missing required argument: plugin');
}
});

test('Verify that taqueria ligo plugin can run ligo test using taq test <sourceFile> command adding --plugin ligo to the command', async () => {
try {
// 2. Run taq test ${testFileName} with --plugin parameter
const { stdout, stderr } = await exec(`taq test hello-tacos-tests.mligo --plugin ligo`, {
cwd: `./${taqueriaProjectPath}`,
});
expect(stdout).toContain('All tests passed');
} catch (error) {
throw new Error(`error: ${error}`);
}
});

// Remove all files from artifacts folder without removing folder itself
afterEach(async () => {
try {
const files = await fsPromises.readdir(`${taqueriaProjectPath}/artifacts/`);
for (const file of files) {
await fsPromises.rm(path.join(`${taqueriaProjectPath}/artifacts/`, file));
}
} catch (error) {
throw new Error(`error: ${error}`);
}
});

// Clean up process to remove taquified project folder
// Comment if need to debug
afterAll(async () => {
try {
fsPromises.rm(taqueriaProjectPath, { recursive: true });
} catch (error) {
throw new Error(`error: ${error}`);
}
});
});

0 comments on commit c22e6d0

Please sign in to comment.