-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ecadlabs/metadata-plugin-tests
added metadata and types plugins
- Loading branch information
Showing
12 changed files
with
2,927 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,292 @@ | ||
import { exec as exec1 } from 'child_process'; | ||
import path from 'path'; | ||
import util from 'util'; | ||
const exec = util.promisify(exec1); | ||
|
||
import { prepareEnvironment } from '@gmrchk/cli-testing-library'; | ||
|
||
describe('Contract Types Plugin E2E Testing for Taqueria CLI', () => { | ||
|
||
jest.setTimeout(30000); | ||
|
||
test('contract types plugin will offer help', async () => { | ||
const { execute, spawn, cleanup } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', '--help --projectDir=./test-project'); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Commands:'])); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test.skip('1635 - generate types offers contextual help', async () => { | ||
const { execute, spawn, cleanup } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', 'generate types --help --projectDir=./test-project'); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Generate types for a contract to be used with taquito'])); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test.skip('1635 - gen offers contextual help', async () => { | ||
const { execute, spawn, cleanup } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', 'gen --help --projectDir=./test-project'); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Generate types for a contract to be used with taquito'])); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types will only output the typeScriptDir and will not create a types dir when no contracts exist', async () => { | ||
const { execute, spawn, cleanup, ls } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
|
||
const { stdout: stdout1 } = await execute('taq', 'generate types', './test-project'); | ||
expect(stdout1).toContain(`generateTypes { typescriptDir: 'types' }`); | ||
|
||
expect(await ls('./test-project/')).not.toContain('types'); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types types can compile one contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; | ||
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); | ||
|
||
const {} = await execute('taq', 'compile increment.jsligo', './test-project'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', 'generate types types', './test-project'); | ||
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); | ||
expect(stdout2).toEqual( | ||
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), | ||
); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); | ||
|
||
expect(await ls('./test-project/')).toContain('types'); | ||
expect(await ls('./test-project/types')).toContain('increment.code.ts'); | ||
expect(await ls('./test-project/types')).toContain('increment.types.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-aliases.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-utils.ts'); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('gentypes types can compile one contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; | ||
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); | ||
|
||
const {} = await execute('taq', 'compile increment.jsligo', './test-project'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', 'gentypes types', './test-project'); | ||
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); | ||
expect(stdout2).toEqual( | ||
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), | ||
); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); | ||
|
||
expect(await ls('./test-project/')).toContain('types'); | ||
expect(await ls('./test-project/types')).toContain('increment.code.ts'); | ||
expect(await ls('./test-project/types')).toContain('increment.types.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-aliases.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-utils.ts'); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('gen types can compile one contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; | ||
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); | ||
|
||
const {} = await execute('taq', 'compile increment.jsligo', './test-project'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', 'gen types', './test-project'); | ||
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); | ||
expect(stdout2).toEqual( | ||
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), | ||
); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); | ||
|
||
expect(await ls('./test-project/')).toContain('types'); | ||
expect(await ls('./test-project/types')).toContain('increment.code.ts'); | ||
expect(await ls('./test-project/types')).toContain('increment.types.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-aliases.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-utils.ts'); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types -t "file" can compile one contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; | ||
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); | ||
|
||
const {} = await execute('taq', 'compile increment.jsligo', './test-project'); | ||
|
||
const { stdout: stdout2 } = await execute('taq', 'generate types -t "file"', './test-project'); | ||
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); | ||
expect(stdout2).toEqual( | ||
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), | ||
); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); | ||
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); | ||
|
||
expect(await ls('./test-project/')).toContain('types'); | ||
expect(await ls('./test-project/types')).toContain('increment.code.ts'); | ||
expect(await ls('./test-project/types')).toContain('increment.types.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-aliases.ts'); | ||
expect(await ls('./test-project/types')).toContain('type-utils.ts'); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types can compile an Auction contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const tz_file = await (await exec(`cat src/test-data/contracts/example-contract-1.tz`)) | ||
.stdout; | ||
await writeFile('./test-project/artifacts/example-contract-1.tz', tz_file); | ||
const expected_types_file = | ||
await (await exec(`cat src/test-data/types-file/example-contract-1.types.ts`)).stdout; | ||
|
||
const {} = await execute('taq', 'generate types', './test-project'); | ||
const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-contract-1.types.ts')); | ||
|
||
expect(generated_types_file).toBe(expected_types_file); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types can compile an FA2 contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const tz_file = await (await exec(`cat src/test-data/contracts/example-contract-2.tz`)) | ||
.stdout; | ||
await writeFile('./test-project/artifacts/example-contract-2.tz', tz_file); | ||
const expected_types_file = | ||
await (await exec(`cat src/test-data/types-file/example-contract-2.types.ts`)).stdout; | ||
|
||
const {} = await execute('taq', 'generate types', './test-project'); | ||
const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-contract-2.types.ts')); | ||
|
||
expect(generated_types_file).toBe(expected_types_file); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types can compile a contract from a sub-directory and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const tz_file = | ||
await (await exec(`cat src/test-data/contracts/subdir/example-contract-0.tz`)).stdout; | ||
await writeFile('./test-project/artifacts/subdir/example-contract-0.tz', tz_file); | ||
const expected_types_file = | ||
await (await exec(`cat src/test-data/types-file/subdir/example-contract-0.types.ts`)) | ||
.stdout; | ||
|
||
const {} = await execute('taq', 'generate types', './test-project'); | ||
const generated_types_file = await readFile( | ||
path.join('./test-project', 'types', 'subdir/example-contract-0.types.ts'), | ||
); | ||
|
||
expect(generated_types_file).toBe(expected_types_file); | ||
|
||
await cleanup(); | ||
}); | ||
|
||
test('generate types can compile a Lambda contract and generate types', async () => { | ||
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); | ||
const { waitForText } = await spawn('taq', 'init test-project'); | ||
await waitForText("Project taq'ified!"); | ||
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); | ||
expect(stdout).toContain('Plugin installed successfully'); | ||
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); | ||
expect(stdout1).toContain('Plugin installed successfully'); | ||
|
||
const tz_file = await (await exec(`cat src/test-data/contracts/example-lambda.tz`)) | ||
.stdout; | ||
await writeFile('./test-project/artifacts/example-lambda.tz', tz_file); | ||
const expected_types_file = | ||
await (await exec(`cat src/test-data/types-file/example-lambda.types.ts`)).stdout; | ||
|
||
const {} = await execute('taq', 'generate types', './test-project'); | ||
const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-lambda.types.ts')); | ||
|
||
expect(generated_types_file).toBe(expected_types_file); | ||
|
||
await cleanup(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.