@taqueria/plugin-jest 0.8.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/common.ts ADDED
@@ -0,0 +1,115 @@
1
+ import { noop, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';
2
+ import { LoadedConfig, RequestArgs, SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';
3
+ import { mkdir, stat, writeFile } from 'fs/promises';
4
+ import { defaults } from 'jest-config';
5
+ import { join, relative } from 'path';
6
+ import * as JestConfig from './config';
7
+
8
+ export type DefaultConfig = typeof defaults;
9
+
10
+ export interface CustomRequestArgs extends RequestArgs.t {
11
+ config: JestConfig.t;
12
+ partition?: string;
13
+ init?: string;
14
+ testPattern?: string;
15
+ }
16
+
17
+ export const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {
18
+ const config = {
19
+ jest: {
20
+ testsRootDir: 'tests',
21
+ },
22
+ ...args.config,
23
+ };
24
+
25
+ return {
26
+ ...args,
27
+ config: JestConfig.create(config),
28
+ };
29
+ };
30
+
31
+ export const getDefaultConfig = (defaultConfig: DefaultConfig) => {
32
+ const settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };
33
+ return (
34
+ `
35
+ module.exports = ${JSON.stringify(settings, null, 4)}
36
+ `
37
+ );
38
+ };
39
+
40
+ export const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {
41
+ const jestRootConfig = getRootConfigAbspath(projectDir);
42
+ return stat(jestRootConfig)
43
+ .catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))
44
+ .then(_ => jestRootConfig);
45
+ };
46
+
47
+ export const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>
48
+ SanitizedAbsPath.create(
49
+ join(projectDir, '.taq', 'jest.config.js'),
50
+ );
51
+
52
+ export const getTestsRootDir = (config: JestConfig.t) => {
53
+ return config.jest.testsRootDir;
54
+ };
55
+
56
+ export const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `
57
+ const parentConfig = require('${rootConfigRelPath}')
58
+
59
+ module.exports = {
60
+ ...parentConfig,
61
+ roots: [
62
+ "${partitionRelpath}"
63
+ ]
64
+ }
65
+ `;
66
+
67
+ export const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);
68
+
69
+ export const getPartitionConfigAbspath = (partitionDir: string) =>
70
+ SanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));
71
+
72
+ export const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) =>
73
+ writeFile(
74
+ getPartitionConfigAbspath(partitionDir),
75
+ toPartitionCfg(
76
+ SanitizedPath.create(relative(partitionDir, partitionDir)),
77
+ SanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),
78
+ ),
79
+ );
80
+
81
+ export const ensurePartitionExists = async (
82
+ partitionDir: SanitizedAbsPath.t,
83
+ projectDir: SanitizedAbsPath.t,
84
+ forceCreate = false,
85
+ ) =>
86
+ ensureRootConfigExists(projectDir)
87
+ .then(_ => stat(partitionDir))
88
+ .then(stats =>
89
+ stats.isFile()
90
+ ? sendAsyncErr(`${partitionDir} is an invalid partition directory`)
91
+ : stats
92
+ )
93
+ .catch(_ => mkdir(partitionDir, { recursive: true }))
94
+ .then(_ => getPartitionConfigAbspath(partitionDir))
95
+ .then(partitionCfgAbsPath =>
96
+ stat(partitionCfgAbsPath)
97
+ .then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)
98
+ .catch(_ => initPartition(partitionDir, projectDir))
99
+ )
100
+ .then(_ => getPartitionConfigAbspath(partitionDir));
101
+
102
+ export const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>
103
+ args.partition
104
+ ? ensurePartitionExists(
105
+ SanitizedAbsPath.create(join(args.projectDir, args.partition)),
106
+ args.projectDir,
107
+ forceCreate,
108
+ )
109
+ : ensurePartitionExists(
110
+ SanitizedAbsPath.create(
111
+ join(args.projectDir, getTestsRootDir(args.config)),
112
+ ),
113
+ args.projectDir,
114
+ forceCreate,
115
+ );
package/config.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { LoadedConfig } from '@taqueria/node-sdk';
2
+ import { z } from 'zod';
3
+
4
+ const jestType: unique symbol = Symbol('jestConfig');
5
+
6
+ const rawSchema = LoadedConfig.rawSchema.extend({
7
+ jest: z.preprocess(
8
+ input => {
9
+ const overrides = typeof input === 'object'
10
+ ? input
11
+ : {};
12
+
13
+ return {
14
+ 'testsRootDir': 'tests',
15
+ ...overrides,
16
+ };
17
+ },
18
+ z.object({
19
+ 'testsRootDir': z.preprocess(
20
+ val => val ?? 'tests',
21
+ z.string().min(1).describe('testsRootDir'),
22
+ ),
23
+ }),
24
+ ),
25
+ });
26
+
27
+ const internalSchema = Object.assign({}, rawSchema);
28
+
29
+ type RawInput = z.infer<typeof rawSchema>;
30
+
31
+ type Input = z.infer<typeof internalSchema>;
32
+
33
+ export interface JestRawConfig extends LoadedConfig.t {
34
+ [jestType]: void;
35
+ }
36
+
37
+ export type JestConfig = Input & JestRawConfig;
38
+
39
+ export type t = JestConfig;
40
+
41
+ export const schema = internalSchema.transform(val => val as JestConfig);
42
+
43
+ export const create = (input: RawInput | unknown) => {
44
+ try {
45
+ const retval = schema.parse(input);
46
+ return retval;
47
+ } catch {
48
+ throw `The .taq/config.json file is invalid.`;
49
+ }
50
+ };
@@ -0,0 +1,112 @@
1
+ // import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';
2
+ import { sendAsyncRes } from '@taqueria/node-sdk';
3
+ import { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';
4
+ import {
5
+ createTestingCodeGenerator,
6
+ normalizeContractName,
7
+ } from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';
8
+ import { readFile, stat, writeFile } from 'fs/promises';
9
+ import { basename, dirname, join } from 'path';
10
+ import { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';
11
+
12
+ type Generator = ReturnType<typeof createTestingCodeGenerator>;
13
+
14
+ interface Opts extends CustomRequestArgs {
15
+ readonly michelsonArtifact: string;
16
+ readonly partition?: string;
17
+ readonly name?: string;
18
+ }
19
+
20
+ const getMichelsonAbspath = (parsedArgs: Opts) => join(parsedArgs.config.artifactsDir, parsedArgs.michelsonArtifact);
21
+
22
+ const ensureMichelsonExists = (parsedArgs: Opts) => {
23
+ const abspath = getMichelsonAbspath(parsedArgs);
24
+ return stat(abspath)
25
+ .then(() => parsedArgs)
26
+ .catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run "taq compile"?`));
27
+ };
28
+
29
+ const getPartition = (parsedArgs: Opts) => {
30
+ const partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);
31
+ return getPartitionAbspath(partition);
32
+ };
33
+
34
+ const getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');
35
+
36
+ const generateContractTypes = (parsedArgs: Opts) =>
37
+ generateContractTypesProcessContractFiles({
38
+ inputTzContractDirectory: parsedArgs.config.artifactsDir,
39
+ inputFiles: [getMichelsonAbspath(parsedArgs)],
40
+ outputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),
41
+ format: 'tz',
42
+ typeAliasMode: 'file',
43
+ }).then(_ => parsedArgs);
44
+
45
+ const getContractName = (parsedArgs: Opts) =>
46
+ parsedArgs.name
47
+ ? parsedArgs.name.trim().replace(/\.ts$/, '')
48
+ : basename(parsedArgs.michelsonArtifact, '.tz');
49
+
50
+ const generateTestSuite = (parsedArgs: Opts) => {
51
+ const michelsonAbspath = getMichelsonAbspath(parsedArgs);
52
+ const contractName = getContractName(parsedArgs);
53
+ const partition = getPartition(parsedArgs);
54
+ const jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);
55
+
56
+ return readFile(michelsonAbspath, { encoding: 'utf-8' })
57
+ .then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))
58
+ .then(createTestingCodeGenerator)
59
+ .then(toJest(contractName))
60
+ .then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))
61
+ .then(() => jestSuiteAbspath);
62
+ };
63
+
64
+ const toJest = (contractName: string) =>
65
+ (generator: Generator) => {
66
+ const methodCalls = generator.methods.map(m => ({
67
+ name: m.name,
68
+ methodCall: generator.generateMethodCall({
69
+ methodName: m.name,
70
+ formatting: {
71
+ indent: 2,
72
+ },
73
+ }),
74
+ storageAccess: generator.generateStorageAccess({ storagePath: '' }),
75
+ }));
76
+ return `
77
+ import { TezosToolkit } from '@taquito/taquito';
78
+ import { char2Bytes } from '@taquito/utils';
79
+ import { tas } from './types/type-aliases';
80
+ import { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';
81
+ import { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';
82
+
83
+ describe('${contractName}', () => {
84
+ const Tezos = new TezosToolkit('RPC_URL');
85
+ let contract: ContractType = undefined as unknown as ContractType;
86
+ beforeAll(async () => {
87
+ ${generator.generateOrigination({ formatting: { indent: 3 } }).code}
88
+ });
89
+
90
+ ${
91
+ methodCalls.map(x => `
92
+ it('should call ${x.name}', async () => {
93
+ ${x.storageAccess.getStorageValueFunctionCode}
94
+ const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();
95
+ ${x.methodCall.code}
96
+ const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();
97
+
98
+ expect(storageValueAfter).toBe('');
99
+ });
100
+ `).join('')
101
+ });
102
+ `;
103
+ };
104
+
105
+ export default (parsedArgs: Opts) => {
106
+ return ensureMichelsonExists(parsedArgs)
107
+ .then(ensureSelectedPartitionExists)
108
+ .then(() => parsedArgs)
109
+ .then(generateContractTypes)
110
+ .then(generateTestSuite)
111
+ .then(outFile => sendAsyncRes(`Test suite generated: ${outFile}`));
112
+ };
package/index.cjs ADDED
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+
3
+ // index.ts
4
+ var import_node_sdk5 = require("@taqueria/node-sdk");
5
+
6
+ // common.ts
7
+ var import_node_sdk2 = require("@taqueria/node-sdk");
8
+ var import_types = require("@taqueria/node-sdk/types");
9
+ var import_promises = require("fs/promises");
10
+ var import_jest_config = require("jest-config");
11
+ var import_path = require("path");
12
+
13
+ // config.ts
14
+ var import_node_sdk = require("@taqueria/node-sdk");
15
+ var import_zod = require("zod");
16
+ var jestType = Symbol("jestConfig");
17
+ var rawSchema = import_node_sdk.LoadedConfig.rawSchema.extend({
18
+ jest: import_zod.z.preprocess(
19
+ (input) => {
20
+ const overrides = typeof input === "object" ? input : {};
21
+ return {
22
+ "testsRootDir": "tests",
23
+ ...overrides
24
+ };
25
+ },
26
+ import_zod.z.object({
27
+ "testsRootDir": import_zod.z.preprocess(
28
+ (val) => val ?? "tests",
29
+ import_zod.z.string().min(1).describe("testsRootDir")
30
+ )
31
+ })
32
+ )
33
+ });
34
+ var internalSchema = Object.assign({}, rawSchema);
35
+ var schema = internalSchema.transform((val) => val);
36
+ var create = (input) => {
37
+ try {
38
+ const retval = schema.parse(input);
39
+ return retval;
40
+ } catch {
41
+ throw `The .taq/config.json file is invalid.`;
42
+ }
43
+ };
44
+
45
+ // common.ts
46
+ var toRequestArgs = (args) => {
47
+ const config = {
48
+ jest: {
49
+ testsRootDir: "tests"
50
+ },
51
+ ...args.config
52
+ };
53
+ return {
54
+ ...args,
55
+ config: create(config)
56
+ };
57
+ };
58
+ var getDefaultConfig = (defaultConfig) => {
59
+ const settings = { ...import_jest_config.defaults, preset: "ts-jest", testEnvironment: "node" };
60
+ return `
61
+ module.exports = ${JSON.stringify(settings, null, 4)}
62
+ `;
63
+ };
64
+ var ensureRootConfigExists = (projectDir) => {
65
+ const jestRootConfig = getRootConfigAbspath(projectDir);
66
+ return (0, import_promises.stat)(jestRootConfig).catch((_) => (0, import_promises.writeFile)(jestRootConfig, getDefaultConfig(import_jest_config.defaults))).then((_) => jestRootConfig);
67
+ };
68
+ var getRootConfigAbspath = (projectDir) => import_types.SanitizedAbsPath.create(
69
+ (0, import_path.join)(projectDir, ".taq", "jest.config.js")
70
+ );
71
+ var getTestsRootDir = (config) => {
72
+ return config.jest.testsRootDir;
73
+ };
74
+ var toPartitionCfg = (partitionRelpath, rootConfigRelPath) => `
75
+ const parentConfig = require('${rootConfigRelPath}')
76
+
77
+ module.exports = {
78
+ ...parentConfig,
79
+ roots: [
80
+ "${partitionRelpath}"
81
+ ]
82
+ }
83
+ `;
84
+ var getPartitionAbspath = (partitionDir) => import_types.SanitizedAbsPath.create(partitionDir);
85
+ var getPartitionConfigAbspath = (partitionDir) => import_types.SanitizedAbsPath.create((0, import_path.join)(partitionDir, "jest.config.js"));
86
+ var initPartition = (partitionDir, projectDir) => (0, import_promises.writeFile)(
87
+ getPartitionConfigAbspath(partitionDir),
88
+ toPartitionCfg(
89
+ import_types.SanitizedPath.create((0, import_path.relative)(partitionDir, partitionDir)),
90
+ import_types.SanitizedPath.create((0, import_path.relative)(partitionDir, getRootConfigAbspath(projectDir)))
91
+ )
92
+ );
93
+ var ensurePartitionExists = async (partitionDir, projectDir, forceCreate = false) => ensureRootConfigExists(projectDir).then((_) => (0, import_promises.stat)(partitionDir)).then(
94
+ (stats) => stats.isFile() ? (0, import_node_sdk2.sendAsyncErr)(`${partitionDir} is an invalid partition directory`) : stats
95
+ ).catch((_) => (0, import_promises.mkdir)(partitionDir, { recursive: true })).then((_) => getPartitionConfigAbspath(partitionDir)).then(
96
+ (partitionCfgAbsPath) => (0, import_promises.stat)(partitionCfgAbsPath).then((_) => forceCreate ? initPartition(partitionDir, projectDir) : void 0).catch((_) => initPartition(partitionDir, projectDir))
97
+ ).then((_) => getPartitionConfigAbspath(partitionDir));
98
+ var ensureSelectedPartitionExists = (args, forceCreate = false) => args.partition ? ensurePartitionExists(
99
+ import_types.SanitizedAbsPath.create((0, import_path.join)(args.projectDir, args.partition)),
100
+ args.projectDir,
101
+ forceCreate
102
+ ) : ensurePartitionExists(
103
+ import_types.SanitizedAbsPath.create(
104
+ (0, import_path.join)(args.projectDir, getTestsRootDir(args.config))
105
+ ),
106
+ args.projectDir,
107
+ forceCreate
108
+ );
109
+
110
+ // contractTestTemplate.ts
111
+ var import_node_sdk3 = require("@taqueria/node-sdk");
112
+ var import_cli_process = require("@taqueria/plugin-contract-types/src/cli-process.js");
113
+ var import_testing_code_generator = require("@taqueria/plugin-contract-types/src/generator/testing-code-generator.js");
114
+ var import_promises2 = require("fs/promises");
115
+ var import_path2 = require("path");
116
+ var getMichelsonAbspath = (parsedArgs) => (0, import_path2.join)(parsedArgs.config.artifactsDir, parsedArgs.michelsonArtifact);
117
+ var ensureMichelsonExists = (parsedArgs) => {
118
+ const abspath = getMichelsonAbspath(parsedArgs);
119
+ return (0, import_promises2.stat)(abspath).then(() => parsedArgs).catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run "taq compile"?`));
120
+ };
121
+ var getPartition = (parsedArgs) => {
122
+ const partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);
123
+ return getPartitionAbspath(partition);
124
+ };
125
+ var getTypesOutputAbspath = (parsedArgs) => (0, import_path2.join)(getPartition(parsedArgs), "types");
126
+ var generateContractTypes = (parsedArgs) => (0, import_cli_process.generateContractTypesProcessContractFiles)({
127
+ inputTzContractDirectory: parsedArgs.config.artifactsDir,
128
+ inputFiles: [getMichelsonAbspath(parsedArgs)],
129
+ outputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),
130
+ format: "tz",
131
+ typeAliasMode: "file"
132
+ }).then((_) => parsedArgs);
133
+ var getContractName = (parsedArgs) => parsedArgs.name ? parsedArgs.name.trim().replace(/\.ts$/, "") : (0, import_path2.basename)(parsedArgs.michelsonArtifact, ".tz");
134
+ var generateTestSuite = (parsedArgs) => {
135
+ const michelsonAbspath = getMichelsonAbspath(parsedArgs);
136
+ const contractName = getContractName(parsedArgs);
137
+ const partition = getPartition(parsedArgs);
138
+ const jestSuiteAbspath = (0, import_path2.join)(partition, `${contractName}.spec.ts`);
139
+ return (0, import_promises2.readFile)(michelsonAbspath, { encoding: "utf-8" }).then((contractSource) => ({ contractSource, contractFormat: "tz" })).then(import_testing_code_generator.createTestingCodeGenerator).then(toJest(contractName)).then((contents) => (0, import_promises2.writeFile)(jestSuiteAbspath, contents, { encoding: "utf-8" })).then(() => jestSuiteAbspath);
140
+ };
141
+ var toJest = (contractName) => (generator) => {
142
+ const methodCalls = generator.methods.map((m) => ({
143
+ name: m.name,
144
+ methodCall: generator.generateMethodCall({
145
+ methodName: m.name,
146
+ formatting: {
147
+ indent: 2
148
+ }
149
+ }),
150
+ storageAccess: generator.generateStorageAccess({ storagePath: "" })
151
+ }));
152
+ return `
153
+ import { TezosToolkit } from '@taquito/taquito';
154
+ import { char2Bytes } from '@taquito/utils';
155
+ import { tas } from './types/type-aliases';
156
+ import { ${(0, import_testing_code_generator.normalizeContractName)(contractName)}ContractType as ContractType } from './types/${contractName}.types';
157
+ import { ${(0, import_testing_code_generator.normalizeContractName)(contractName)}Code as ContractCode } from './types/${contractName}.code';
158
+
159
+ describe('${contractName}', () => {
160
+ const Tezos = new TezosToolkit('RPC_URL');
161
+ let contract: ContractType = undefined as unknown as ContractType;
162
+ beforeAll(async () => {
163
+ ${generator.generateOrigination({ formatting: { indent: 3 } }).code}
164
+ });
165
+
166
+ ${methodCalls.map((x) => `
167
+ it('should call ${x.name}', async () => {
168
+ ${x.storageAccess.getStorageValueFunctionCode}
169
+ const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();
170
+ ${x.methodCall.code}
171
+ const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();
172
+
173
+ expect(storageValueAfter).toBe('');
174
+ });
175
+ `).join("")});
176
+ `;
177
+ };
178
+ var contractTestTemplate_default = (parsedArgs) => {
179
+ return ensureMichelsonExists(parsedArgs).then(ensureSelectedPartitionExists).then(() => parsedArgs).then(generateContractTypes).then(generateTestSuite).then((outFile) => (0, import_node_sdk3.sendAsyncRes)(`Test suite generated: ${outFile}`));
180
+ };
181
+
182
+ // proxy.ts
183
+ var import_node_sdk4 = require("@taqueria/node-sdk");
184
+ var import_execa = require("execa");
185
+ var execCmd = (cmd, args) => {
186
+ var _a, _b;
187
+ const child = (0, import_execa.execa)(cmd, args, {
188
+ shell: true,
189
+ reject: false,
190
+ env: { FORCE_COLOR: "true" }
191
+ });
192
+ (_a = child.stdout) == null ? void 0 : _a.pipe(process.stdout);
193
+ (_b = child.stderr) == null ? void 0 : _b.pipe(process.stderr);
194
+ return child;
195
+ };
196
+ var proxy_default = async (args) => {
197
+ const parsedArgs = toRequestArgs(args);
198
+ return ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false).then((configAbsPath) => {
199
+ if (!parsedArgs.init) {
200
+ const retval = parsedArgs.testPattern ? execCmd("npx", ["jest", "-c", configAbsPath, "--testPathPattern", parsedArgs.testPattern]) : execCmd("npx", ["jest", "-c", configAbsPath]);
201
+ return retval.then((child) => {
202
+ if (child.exitCode === 0)
203
+ return;
204
+ else
205
+ process.exit(child.exitCode);
206
+ });
207
+ }
208
+ return (0, import_node_sdk4.sendAsyncRes)("Initialized successfully.");
209
+ });
210
+ };
211
+
212
+ // index.ts
213
+ import_node_sdk5.Plugin.create((requestArgs) => ({
214
+ schema: "0.1",
215
+ version: "0.4.0",
216
+ alias: "jest",
217
+ tasks: [
218
+ import_node_sdk5.Task.create({
219
+ task: "test",
220
+ command: "test [partition]",
221
+ description: "Setup a directory as a partition to run Jest tests",
222
+ aliases: ["jest"],
223
+ handler: "proxy",
224
+ positionals: [
225
+ import_node_sdk5.PositionalArg.create({
226
+ placeholder: "partition",
227
+ description: "Name of the partition for these tests",
228
+ defaultValue: "tests",
229
+ type: "string"
230
+ })
231
+ ],
232
+ options: [
233
+ import_node_sdk5.Option.create({
234
+ flag: "init",
235
+ shortFlag: "i",
236
+ description: "Initializes the partition for Jest",
237
+ boolean: true
238
+ }),
239
+ import_node_sdk5.Option.create({
240
+ flag: "testPattern",
241
+ shortFlag: "t",
242
+ description: "Run test files that match the provided pattern"
243
+ })
244
+ ]
245
+ })
246
+ ],
247
+ templates: [
248
+ import_node_sdk5.Template.create({
249
+ template: "contract-test",
250
+ command: "contract-test <michelsonArtifact>",
251
+ positionals: [
252
+ import_node_sdk5.PositionalArg.create({
253
+ placeholder: "michelsonArtifact",
254
+ description: "Name of the michelson contract (artifact) to generate tests for",
255
+ required: true,
256
+ type: "string"
257
+ })
258
+ ],
259
+ options: [
260
+ import_node_sdk5.Option.create({
261
+ flag: "partition",
262
+ description: "Partition to place generated test suite",
263
+ type: "string",
264
+ defaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir
265
+ })
266
+ ],
267
+ description: "Generate integration test for a contract",
268
+ handler: contractTestTemplate_default
269
+ })
270
+ ],
271
+ proxy: proxy_default
272
+ }), process.argv);
273
+ //# sourceMappingURL=index.cjs.map
package/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts","common.ts","config.ts","contractTestTemplate.ts","proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport { CustomRequestArgs, toRequestArgs } from './common';\nimport createContractTest from './contractTestTemplate';\nimport proxy from './proxy';\n\nPlugin.create<CustomRequestArgs>(requestArgs => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract-test',\n\t\t\tcommand: 'contract-test <michelsonArtifact>',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'michelsonArtifact',\n\t\t\t\t\tdescription: 'Name of the michelson contract (artifact) to generate tests for',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'partition',\n\t\t\t\t\tdescription: 'Partition to place generated test suite',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,\n\t\t\t\t}),\n\t\t\t],\n\t\t\tdescription: 'Generate integration test for a contract',\n\t\t\thandler: createContractTest,\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { LoadedConfig, RequestArgs, SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\nimport * as JestConfig from './config';\n\nexport type DefaultConfig = typeof defaults;\n\nexport interface CustomRequestArgs extends RequestArgs.t {\n\tconfig: JestConfig.t;\n\tpartition?: string;\n\tinit?: string;\n\ttestPattern?: string;\n}\n\nexport const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {\n\tconst config = {\n\t\tjest: {\n\t\t\ttestsRootDir: 'tests',\n\t\t},\n\t\t...args.config,\n\t};\n\n\treturn {\n\t\t...args,\n\t\tconfig: JestConfig.create(config),\n\t};\n};\n\nexport const getDefaultConfig = (defaultConfig: DefaultConfig) => {\n\tconst settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };\n\treturn (\n\t\t`\nmodule.exports = ${JSON.stringify(settings, null, 4)}\n`\n\t);\n};\n\nexport const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nexport const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nexport const getTestsRootDir = (config: JestConfig.t) => {\n\treturn config.jest.testsRootDir;\n};\n\nexport const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nexport const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nexport const getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nexport const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) =>\n\twriteFile(\n\t\tgetPartitionConfigAbspath(partitionDir),\n\t\ttoPartitionCfg(\n\t\t\tSanitizedPath.create(relative(partitionDir, partitionDir)),\n\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t),\n\t);\n\nexport const ensurePartitionExists = async (\n\tpartitionDir: SanitizedAbsPath.t,\n\tprojectDir: SanitizedAbsPath.t,\n\tforceCreate = false,\n) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)\n\t\t\t\t.catch(_ => initPartition(partitionDir, projectDir))\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nexport const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>\n\targs.partition\n\t\t? ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\targs.projectDir,\n\t\t\tforceCreate,\n\t\t)\n\t\t: ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\targs.projectDir,\n\t\t\tforceCreate,\n\t\t);\n","import { LoadedConfig } from '@taqueria/node-sdk';\nimport { z } from 'zod';\n\nconst jestType: unique symbol = Symbol('jestConfig');\n\nconst rawSchema = LoadedConfig.rawSchema.extend({\n\tjest: z.preprocess(\n\t\tinput => {\n\t\t\tconst overrides = typeof input === 'object'\n\t\t\t\t? input\n\t\t\t\t: {};\n\n\t\t\treturn {\n\t\t\t\t'testsRootDir': 'tests',\n\t\t\t\t...overrides,\n\t\t\t};\n\t\t},\n\t\tz.object({\n\t\t\t'testsRootDir': z.preprocess(\n\t\t\t\tval => val ?? 'tests',\n\t\t\t\tz.string().min(1).describe('testsRootDir'),\n\t\t\t),\n\t\t}),\n\t),\n});\n\nconst internalSchema = Object.assign({}, rawSchema);\n\ntype RawInput = z.infer<typeof rawSchema>;\n\ntype Input = z.infer<typeof internalSchema>;\n\nexport interface JestRawConfig extends LoadedConfig.t {\n\t[jestType]: void;\n}\n\nexport type JestConfig = Input & JestRawConfig;\n\nexport type t = JestConfig;\n\nexport const schema = internalSchema.transform(val => val as JestConfig);\n\nexport const create = (input: RawInput | unknown) => {\n\ttry {\n\t\tconst retval = schema.parse(input);\n\t\treturn retval;\n\t} catch {\n\t\tthrow `The .taq/config.json file is invalid.`;\n\t}\n};\n","// import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';\nimport { sendAsyncRes } from '@taqueria/node-sdk';\nimport { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';\nimport {\n\tcreateTestingCodeGenerator,\n\tnormalizeContractName,\n} from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';\nimport { readFile, stat, writeFile } from 'fs/promises';\nimport { basename, dirname, join } from 'path';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';\n\ntype Generator = ReturnType<typeof createTestingCodeGenerator>;\n\ninterface Opts extends CustomRequestArgs {\n\treadonly michelsonArtifact: string;\n\treadonly partition?: string;\n\treadonly name?: string;\n}\n\nconst getMichelsonAbspath = (parsedArgs: Opts) => join(parsedArgs.config.artifactsDir, parsedArgs.michelsonArtifact);\n\nconst ensureMichelsonExists = (parsedArgs: Opts) => {\n\tconst abspath = getMichelsonAbspath(parsedArgs);\n\treturn stat(abspath)\n\t\t.then(() => parsedArgs)\n\t\t.catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run \"taq compile\"?`));\n};\n\nconst getPartition = (parsedArgs: Opts) => {\n\tconst partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);\n\treturn getPartitionAbspath(partition);\n};\n\nconst getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');\n\nconst generateContractTypes = (parsedArgs: Opts) =>\n\tgenerateContractTypesProcessContractFiles({\n\t\tinputTzContractDirectory: parsedArgs.config.artifactsDir,\n\t\tinputFiles: [getMichelsonAbspath(parsedArgs)],\n\t\toutputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),\n\t\tformat: 'tz',\n\t\ttypeAliasMode: 'file',\n\t}).then(_ => parsedArgs);\n\nconst getContractName = (parsedArgs: Opts) =>\n\tparsedArgs.name\n\t\t? parsedArgs.name.trim().replace(/\\.ts$/, '')\n\t\t: basename(parsedArgs.michelsonArtifact, '.tz');\n\nconst generateTestSuite = (parsedArgs: Opts) => {\n\tconst michelsonAbspath = getMichelsonAbspath(parsedArgs);\n\tconst contractName = getContractName(parsedArgs);\n\tconst partition = getPartition(parsedArgs);\n\tconst jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);\n\n\treturn readFile(michelsonAbspath, { encoding: 'utf-8' })\n\t\t.then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))\n\t\t.then(createTestingCodeGenerator)\n\t\t.then(toJest(contractName))\n\t\t.then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))\n\t\t.then(() => jestSuiteAbspath);\n};\n\nconst toJest = (contractName: string) =>\n\t(generator: Generator) => {\n\t\tconst methodCalls = generator.methods.map(m => ({\n\t\t\tname: m.name,\n\t\t\tmethodCall: generator.generateMethodCall({\n\t\t\t\tmethodName: m.name,\n\t\t\t\tformatting: {\n\t\t\t\t\tindent: 2,\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstorageAccess: generator.generateStorageAccess({ storagePath: '' }),\n\t\t}));\n\t\treturn `\nimport { TezosToolkit } from '@taquito/taquito';\nimport { char2Bytes } from '@taquito/utils';\nimport { tas } from './types/type-aliases';\nimport { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';\nimport { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';\n\ndescribe('${contractName}', () => {\n const Tezos = new TezosToolkit('RPC_URL');\n let contract: ContractType = undefined as unknown as ContractType;\n beforeAll(async () => {\n ${generator.generateOrigination({ formatting: { indent: 3 } }).code}\n });\n\n${\n\t\t\tmethodCalls.map(x => `\n it('should call ${x.name}', async () => {\n ${x.storageAccess.getStorageValueFunctionCode}\n const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();\n ${x.methodCall.code}\n const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();\n\n expect(storageValueAfter).toBe('');\n });\n`).join('')\n\t\t});\n`;\n\t};\n\nexport default (parsedArgs: Opts) => {\n\treturn ensureMichelsonExists(parsedArgs)\n\t\t.then(ensureSelectedPartitionExists)\n\t\t.then(() => parsedArgs)\n\t\t.then(generateContractTypes)\n\t\t.then(generateTestSuite)\n\t\t.then(outFile => sendAsyncRes(`Test suite generated: ${outFile}`));\n};\n","import { sendAsyncRes } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { execa } from 'execa';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\nexport default async (args: RequestArgs.t) => {\n\tconst parsedArgs = toRequestArgs(args);\n\treturn ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)\n\t\t.then(configAbsPath => {\n\t\t\tif (!parsedArgs.init) {\n\t\t\t\tconst retval = parsedArgs.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],"mappings":";;;AAAA,IAAAA,mBAA8D;;;ACA9D,IAAAC,mBAAiD;AACjD,mBAA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,aAAa;AAAA,UACb,SAAS;AAAA,QACV,CAAC;AAAA,QACD,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,WAAW;AAAA,UACX,aAAa;AAAA,QACd,CAAC;AAAA,MACF;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACV,0BAAS,OAAO;AAAA,MACf,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,+BAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,UAAU;AAAA,UACV,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,MAAM;AAAA,UACN,cAAc,cAAc,WAAW,EAAE,OAAO,KAAK;AAAA,QACtD,CAAC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,SAAS;AAAA,IACV,CAAC;AAAA,EACF;AAAA,EACA;AACD,IAAI,QAAQ,IAAI;","names":["import_node_sdk","import_node_sdk","import_node_sdk","import_promises","import_path","import_node_sdk"]}
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+
package/index.js CHANGED
@@ -1,29 +1,75 @@
1
- import {Plugin as $d3MIr$Plugin, Task as $d3MIr$Task, PositionalArg as $d3MIr$PositionalArg, Option as $d3MIr$Option, sendAsyncErr as $d3MIr$sendAsyncErr, sendAsyncRes as $d3MIr$sendAsyncRes} from "@taqueria/node-sdk";
2
- import {SanitizedAbsPath as $d3MIr$SanitizedAbsPath, SanitizedPath as $d3MIr$SanitizedPath} from "@taqueria/node-sdk/types";
3
- import {execa as $d3MIr$execa} from "execa";
4
- import {stat as $d3MIr$stat, writeFile as $d3MIr$writeFile, mkdir as $d3MIr$mkdir} from "fs/promises";
5
- import {defaults as $d3MIr$defaults} from "jest-config";
6
- import {join as $d3MIr$join, relative as $d3MIr$relative} from "path";
7
-
8
-
9
-
10
-
11
-
1
+ // index.ts
2
+ import { Option, Plugin, PositionalArg, Task, Template } from "@taqueria/node-sdk";
12
3
 
4
+ // common.ts
5
+ import { sendAsyncErr } from "@taqueria/node-sdk";
6
+ import { SanitizedAbsPath, SanitizedPath } from "@taqueria/node-sdk/types";
7
+ import { mkdir, stat, writeFile } from "fs/promises";
8
+ import { defaults } from "jest-config";
9
+ import { join, relative } from "path";
13
10
 
11
+ // config.ts
12
+ import { LoadedConfig } from "@taqueria/node-sdk";
13
+ import { z } from "zod";
14
+ var jestType = Symbol("jestConfig");
15
+ var rawSchema = LoadedConfig.rawSchema.extend({
16
+ jest: z.preprocess(
17
+ (input) => {
18
+ const overrides = typeof input === "object" ? input : {};
19
+ return {
20
+ "testsRootDir": "tests",
21
+ ...overrides
22
+ };
23
+ },
24
+ z.object({
25
+ "testsRootDir": z.preprocess(
26
+ (val) => val ?? "tests",
27
+ z.string().min(1).describe("testsRootDir")
28
+ )
29
+ })
30
+ )
31
+ });
32
+ var internalSchema = Object.assign({}, rawSchema);
33
+ var schema = internalSchema.transform((val) => val);
34
+ var create = (input) => {
35
+ try {
36
+ const retval = schema.parse(input);
37
+ return retval;
38
+ } catch {
39
+ throw `The .taq/config.json file is invalid.`;
40
+ }
41
+ };
14
42
 
15
- const $74485658d1dbcd36$var$getDefaultConfig = (defaultConfig)=>`
16
- module.exports = ${JSON.stringify((0, $d3MIr$defaults), null, 4)}
43
+ // common.ts
44
+ var toRequestArgs = (args) => {
45
+ const config = {
46
+ jest: {
47
+ testsRootDir: "tests"
48
+ },
49
+ ...args.config
50
+ };
51
+ return {
52
+ ...args,
53
+ config: create(config)
54
+ };
55
+ };
56
+ var getDefaultConfig = (defaultConfig) => {
57
+ const settings = { ...defaults, preset: "ts-jest", testEnvironment: "node" };
58
+ return `
59
+ module.exports = ${JSON.stringify(settings, null, 4)}
17
60
  `;
18
- const $74485658d1dbcd36$var$ensureRootConfigExists = (projectDir)=>{
19
- const jestRootConfig = $74485658d1dbcd36$var$getRootConfigAbspath(projectDir);
20
- return (0, $d3MIr$stat)(jestRootConfig).catch((_)=>(0, $d3MIr$writeFile)(jestRootConfig, $74485658d1dbcd36$var$getDefaultConfig((0, $d3MIr$defaults)))).then((_)=>jestRootConfig);
21
61
  };
22
- const $74485658d1dbcd36$var$getRootConfigAbspath = (projectDir)=>(0, $d3MIr$SanitizedAbsPath).create((0, $d3MIr$join)(projectDir, ".taq", "jest.config.js"));
23
- const $74485658d1dbcd36$var$getTestsRootDir = (config)=>{
24
- return config.jestTestsRootDir || "tests";
62
+ var ensureRootConfigExists = (projectDir) => {
63
+ const jestRootConfig = getRootConfigAbspath(projectDir);
64
+ return stat(jestRootConfig).catch((_) => writeFile(jestRootConfig, getDefaultConfig(defaults))).then((_) => jestRootConfig);
65
+ };
66
+ var getRootConfigAbspath = (projectDir) => SanitizedAbsPath.create(
67
+ join(projectDir, ".taq", "jest.config.js")
68
+ );
69
+ var getTestsRootDir = (config) => {
70
+ return config.jest.testsRootDir;
25
71
  };
26
- const $74485658d1dbcd36$var$toPartitionCfg = (partitionRelpath, rootConfigRelPath)=>`
72
+ var toPartitionCfg = (partitionRelpath, rootConfigRelPath) => `
27
73
  const parentConfig = require('${rootConfigRelPath}')
28
74
 
29
75
  module.exports = {
@@ -33,87 +79,196 @@ module.exports = {
33
79
  ]
34
80
  }
35
81
  `;
36
- const $74485658d1dbcd36$var$getPartitionAbspath = (partitionDir)=>(0, $d3MIr$SanitizedAbsPath).create(partitionDir);
37
- const $74485658d1dbcd36$var$getPartitionConfigAbspath = (partitionDir)=>(0, $d3MIr$SanitizedAbsPath).create((0, $d3MIr$join)(partitionDir, "jest.config.js"));
38
- const $74485658d1dbcd36$var$createPartition = async (partitionDir, projectDir)=>$74485658d1dbcd36$var$ensureRootConfigExists(projectDir).then((_)=>(0, $d3MIr$stat)(partitionDir)).then((stats)=>stats.isFile() ? (0, $d3MIr$sendAsyncErr)(`${partitionDir} is an invalid partition directory`) : stats).catch((_)=>(0, $d3MIr$mkdir)(partitionDir, {
39
- recursive: true
40
- })).then((_)=>$74485658d1dbcd36$var$getPartitionConfigAbspath(partitionDir)).then((partitionCfgAbsPath)=>(0, $d3MIr$stat)(partitionCfgAbsPath).catch((_)=>(0, $d3MIr$writeFile)(partitionCfgAbsPath, $74485658d1dbcd36$var$toPartitionCfg((0, $d3MIr$SanitizedPath).create((0, $d3MIr$relative)(partitionDir, partitionDir)), (0, $d3MIr$SanitizedPath).create((0, $d3MIr$relative)(partitionDir, $74485658d1dbcd36$var$getRootConfigAbspath(projectDir))))))).then((_)=>$74485658d1dbcd36$var$getPartitionConfigAbspath(partitionDir));
41
- const $74485658d1dbcd36$var$ensurePartitionExists = (args)=>args.partition ? $74485658d1dbcd36$var$createPartition((0, $d3MIr$SanitizedAbsPath).create((0, $d3MIr$join)(args.projectDir, args.partition)), args.projectDir) : $74485658d1dbcd36$var$createPartition((0, $d3MIr$SanitizedAbsPath).create((0, $d3MIr$join)(args.projectDir, $74485658d1dbcd36$var$getTestsRootDir(args.config))), args.projectDir);
42
- const $74485658d1dbcd36$var$execCmd = (cmd, args)=>{
43
- const child = (0, $d3MIr$execa)(cmd, args, {
44
- shell: true,
45
- reject: false,
46
- env: {
47
- FORCE_COLOR: "true"
48
- }
49
- });
50
- child.stdout?.pipe(process.stdout);
51
- child.stderr?.pipe(process.stderr);
52
- return child;
82
+ var getPartitionAbspath = (partitionDir) => SanitizedAbsPath.create(partitionDir);
83
+ var getPartitionConfigAbspath = (partitionDir) => SanitizedAbsPath.create(join(partitionDir, "jest.config.js"));
84
+ var initPartition = (partitionDir, projectDir) => writeFile(
85
+ getPartitionConfigAbspath(partitionDir),
86
+ toPartitionCfg(
87
+ SanitizedPath.create(relative(partitionDir, partitionDir)),
88
+ SanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir)))
89
+ )
90
+ );
91
+ var ensurePartitionExists = async (partitionDir, projectDir, forceCreate = false) => ensureRootConfigExists(projectDir).then((_) => stat(partitionDir)).then(
92
+ (stats) => stats.isFile() ? sendAsyncErr(`${partitionDir} is an invalid partition directory`) : stats
93
+ ).catch((_) => mkdir(partitionDir, { recursive: true })).then((_) => getPartitionConfigAbspath(partitionDir)).then(
94
+ (partitionCfgAbsPath) => stat(partitionCfgAbsPath).then((_) => forceCreate ? initPartition(partitionDir, projectDir) : void 0).catch((_) => initPartition(partitionDir, projectDir))
95
+ ).then((_) => getPartitionConfigAbspath(partitionDir));
96
+ var ensureSelectedPartitionExists = (args, forceCreate = false) => args.partition ? ensurePartitionExists(
97
+ SanitizedAbsPath.create(join(args.projectDir, args.partition)),
98
+ args.projectDir,
99
+ forceCreate
100
+ ) : ensurePartitionExists(
101
+ SanitizedAbsPath.create(
102
+ join(args.projectDir, getTestsRootDir(args.config))
103
+ ),
104
+ args.projectDir,
105
+ forceCreate
106
+ );
107
+
108
+ // contractTestTemplate.ts
109
+ import { sendAsyncRes as sendAsyncRes2 } from "@taqueria/node-sdk";
110
+ import { generateContractTypesProcessContractFiles } from "@taqueria/plugin-contract-types/src/cli-process.js";
111
+ import {
112
+ createTestingCodeGenerator,
113
+ normalizeContractName
114
+ } from "@taqueria/plugin-contract-types/src/generator/testing-code-generator.js";
115
+ import { readFile, stat as stat2, writeFile as writeFile2 } from "fs/promises";
116
+ import { basename, join as join2 } from "path";
117
+ var getMichelsonAbspath = (parsedArgs) => join2(parsedArgs.config.artifactsDir, parsedArgs.michelsonArtifact);
118
+ var ensureMichelsonExists = (parsedArgs) => {
119
+ const abspath = getMichelsonAbspath(parsedArgs);
120
+ return stat2(abspath).then(() => parsedArgs).catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run "taq compile"?`));
53
121
  };
54
- var $74485658d1dbcd36$export$2e2bcd8739ae039 = async (args)=>{
55
- const opts = args;
56
- return $74485658d1dbcd36$var$ensurePartitionExists(opts).then((configAbsPath)=>{
57
- if (!opts.init) {
58
- const retval = opts.testPattern ? $74485658d1dbcd36$var$execCmd("npx", [
59
- "jest",
60
- "-c",
61
- configAbsPath,
62
- "--testPathPattern",
63
- opts.testPattern
64
- ]) : $74485658d1dbcd36$var$execCmd("npx", [
65
- "jest",
66
- "-c",
67
- configAbsPath
68
- ]);
69
- return retval.then((child)=>{
70
- if (child.exitCode === 0) return;
71
- else process.exit(child.exitCode);
72
- });
73
- }
74
- return (0, $d3MIr$sendAsyncRes)("Initialized successfully.");
75
- });
122
+ var getPartition = (parsedArgs) => {
123
+ const partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);
124
+ return getPartitionAbspath(partition);
125
+ };
126
+ var getTypesOutputAbspath = (parsedArgs) => join2(getPartition(parsedArgs), "types");
127
+ var generateContractTypes = (parsedArgs) => generateContractTypesProcessContractFiles({
128
+ inputTzContractDirectory: parsedArgs.config.artifactsDir,
129
+ inputFiles: [getMichelsonAbspath(parsedArgs)],
130
+ outputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),
131
+ format: "tz",
132
+ typeAliasMode: "file"
133
+ }).then((_) => parsedArgs);
134
+ var getContractName = (parsedArgs) => parsedArgs.name ? parsedArgs.name.trim().replace(/\.ts$/, "") : basename(parsedArgs.michelsonArtifact, ".tz");
135
+ var generateTestSuite = (parsedArgs) => {
136
+ const michelsonAbspath = getMichelsonAbspath(parsedArgs);
137
+ const contractName = getContractName(parsedArgs);
138
+ const partition = getPartition(parsedArgs);
139
+ const jestSuiteAbspath = join2(partition, `${contractName}.spec.ts`);
140
+ return readFile(michelsonAbspath, { encoding: "utf-8" }).then((contractSource) => ({ contractSource, contractFormat: "tz" })).then(createTestingCodeGenerator).then(toJest(contractName)).then((contents) => writeFile2(jestSuiteAbspath, contents, { encoding: "utf-8" })).then(() => jestSuiteAbspath);
76
141
  };
142
+ var toJest = (contractName) => (generator) => {
143
+ const methodCalls = generator.methods.map((m) => ({
144
+ name: m.name,
145
+ methodCall: generator.generateMethodCall({
146
+ methodName: m.name,
147
+ formatting: {
148
+ indent: 2
149
+ }
150
+ }),
151
+ storageAccess: generator.generateStorageAccess({ storagePath: "" })
152
+ }));
153
+ return `
154
+ import { TezosToolkit } from '@taquito/taquito';
155
+ import { char2Bytes } from '@taquito/utils';
156
+ import { tas } from './types/type-aliases';
157
+ import { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';
158
+ import { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';
77
159
 
160
+ describe('${contractName}', () => {
161
+ const Tezos = new TezosToolkit('RPC_URL');
162
+ let contract: ContractType = undefined as unknown as ContractType;
163
+ beforeAll(async () => {
164
+ ${generator.generateOrigination({ formatting: { indent: 3 } }).code}
165
+ });
78
166
 
79
- (0, $d3MIr$Plugin).create(()=>({
80
- schema: "0.1",
81
- version: "0.4.0",
82
- alias: "jest",
83
- tasks: [
84
- (0, $d3MIr$Task).create({
85
- task: "test",
86
- command: "test [partition]",
87
- description: "Setup a directory as a partition to run Jest tests",
88
- aliases: [
89
- "jest"
90
- ],
91
- handler: "proxy",
92
- positionals: [
93
- (0, $d3MIr$PositionalArg).create({
94
- placeholder: "partition",
95
- description: "Name of the partition for these tests",
96
- defaultValue: "tests",
97
- type: "string"
98
- }),
99
- ],
100
- options: [
101
- (0, $d3MIr$Option).create({
102
- flag: "init",
103
- shortFlag: "i",
104
- description: "Initializes the partition for Jest",
105
- boolean: true
106
- }),
107
- (0, $d3MIr$Option).create({
108
- flag: "testPattern",
109
- shortFlag: "t",
110
- description: "Run test files that match the provided pattern"
111
- }),
112
- ]
113
- }),
114
- ],
115
- proxy: $74485658d1dbcd36$export$2e2bcd8739ae039
116
- }), process.argv);
167
+ ${methodCalls.map((x) => `
168
+ it('should call ${x.name}', async () => {
169
+ ${x.storageAccess.getStorageValueFunctionCode}
170
+ const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();
171
+ ${x.methodCall.code}
172
+ const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();
173
+
174
+ expect(storageValueAfter).toBe('');
175
+ });
176
+ `).join("")});
177
+ `;
178
+ };
179
+ var contractTestTemplate_default = (parsedArgs) => {
180
+ return ensureMichelsonExists(parsedArgs).then(ensureSelectedPartitionExists).then(() => parsedArgs).then(generateContractTypes).then(generateTestSuite).then((outFile) => sendAsyncRes2(`Test suite generated: ${outFile}`));
181
+ };
117
182
 
183
+ // proxy.ts
184
+ import { sendAsyncRes as sendAsyncRes3 } from "@taqueria/node-sdk";
185
+ import { execa } from "execa";
186
+ var execCmd = (cmd, args) => {
187
+ var _a, _b;
188
+ const child = execa(cmd, args, {
189
+ shell: true,
190
+ reject: false,
191
+ env: { FORCE_COLOR: "true" }
192
+ });
193
+ (_a = child.stdout) == null ? void 0 : _a.pipe(process.stdout);
194
+ (_b = child.stderr) == null ? void 0 : _b.pipe(process.stderr);
195
+ return child;
196
+ };
197
+ var proxy_default = async (args) => {
198
+ const parsedArgs = toRequestArgs(args);
199
+ return ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false).then((configAbsPath) => {
200
+ if (!parsedArgs.init) {
201
+ const retval = parsedArgs.testPattern ? execCmd("npx", ["jest", "-c", configAbsPath, "--testPathPattern", parsedArgs.testPattern]) : execCmd("npx", ["jest", "-c", configAbsPath]);
202
+ return retval.then((child) => {
203
+ if (child.exitCode === 0)
204
+ return;
205
+ else
206
+ process.exit(child.exitCode);
207
+ });
208
+ }
209
+ return sendAsyncRes3("Initialized successfully.");
210
+ });
211
+ };
118
212
 
119
- //# sourceMappingURL=index.js.map
213
+ // index.ts
214
+ Plugin.create((requestArgs) => ({
215
+ schema: "0.1",
216
+ version: "0.4.0",
217
+ alias: "jest",
218
+ tasks: [
219
+ Task.create({
220
+ task: "test",
221
+ command: "test [partition]",
222
+ description: "Setup a directory as a partition to run Jest tests",
223
+ aliases: ["jest"],
224
+ handler: "proxy",
225
+ positionals: [
226
+ PositionalArg.create({
227
+ placeholder: "partition",
228
+ description: "Name of the partition for these tests",
229
+ defaultValue: "tests",
230
+ type: "string"
231
+ })
232
+ ],
233
+ options: [
234
+ Option.create({
235
+ flag: "init",
236
+ shortFlag: "i",
237
+ description: "Initializes the partition for Jest",
238
+ boolean: true
239
+ }),
240
+ Option.create({
241
+ flag: "testPattern",
242
+ shortFlag: "t",
243
+ description: "Run test files that match the provided pattern"
244
+ })
245
+ ]
246
+ })
247
+ ],
248
+ templates: [
249
+ Template.create({
250
+ template: "contract-test",
251
+ command: "contract-test <michelsonArtifact>",
252
+ positionals: [
253
+ PositionalArg.create({
254
+ placeholder: "michelsonArtifact",
255
+ description: "Name of the michelson contract (artifact) to generate tests for",
256
+ required: true,
257
+ type: "string"
258
+ })
259
+ ],
260
+ options: [
261
+ Option.create({
262
+ flag: "partition",
263
+ description: "Partition to place generated test suite",
264
+ type: "string",
265
+ defaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir
266
+ })
267
+ ],
268
+ description: "Generate integration test for a contract",
269
+ handler: contractTestTemplate_default
270
+ })
271
+ ],
272
+ proxy: proxy_default
273
+ }), process.argv);
274
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA;ACAA;;;;;;AAoBA,MAAM,sCAAgB,GAAG,CAAC,aAA4B,GAAK,CAAC;iBAC3C,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA,GAAA,eAAQ,CAAA,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC,AAAC;AAEF,MAAM,4CAAsB,GAAG,CAAC,UAA8B,GAAK;IAClE,MAAM,cAAc,GAAG,0CAAoB,CAAC,UAAU,CAAC,AAAC;IACxD,OAAO,CAAA,GAAA,WAAI,CAAA,CAAC,cAAc,CAAC,CACzB,KAAK,CAAC,CAAA,CAAC,GAAI,CAAA,GAAA,gBAAS,CAAA,CAAC,cAAc,EAAE,sCAAgB,CAAC,CAAA,GAAA,eAAQ,CAAA,CAAC,CAAC,CAAC,CACjE,IAAI,CAAC,CAAA,CAAC,GAAI,cAAc,CAAC,CAAC;CAC5B,AAAC;AAEF,MAAM,0CAAoB,GAAG,CAAC,UAA8B,GAC3D,CAAA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wBACpB,WAAW,EAAE,WAAW;wBACxB,WAAW,EAAE,uCAAuC;wBACpD,YAAY,EAAE,OAAO;wBACrB,IAAI,EAAE,QAAQ;qBACd,CAAC;iBACF;gBACD,OAAO,EAAE;oBACR,CAAA,GAAA,aAAM,CAAA,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,MAAM;wBACZ,SAAS,EAAE,GAAG;wBACd,WAAW,EAAE,oCAAoC;wBACjD,OAAO,EAAE,IAAI;qBACb,CAAC;oBACF,CAAA,GAAA,aAAM,CAAA,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,aAAa;wBACnB,SAAS,EAAE,GAAG;wBACd,WAAW,EAAE,gDAAgD;qBAC7D,CAAC;iBACF;aACD,CAAC;SACF;eACD,wCAAK;KACL,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["taqueria-plugin-jest/index.ts","taqueria-plugin-jest/proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task } from '@taqueria/node-sdk';\nimport proxy from './proxy';\n\nPlugin.create(() => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { LoadedConfig, RequestArgs, SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { execa } from 'execa';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\n\ntype DefaultConfig = typeof defaults;\n\ninterface CustomConfig extends LoadedConfig.t {\n\treadonly jestTestsRootDir?: string;\n}\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\treadonly config: CustomConfig;\n\treadonly init: boolean;\n\treadonly partition: string;\n\treadonly testPattern: string;\n}\n\nconst getDefaultConfig = (defaultConfig: DefaultConfig) => `\nmodule.exports = ${JSON.stringify(defaults, null, 4)}\n`;\n\nconst ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nconst getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nconst getTestsRootDir = (config: CustomConfig) => {\n\treturn config.jestTestsRootDir || 'tests';\n};\n\nconst toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nconst getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nconst getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nconst createPartition = async (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.catch(_ =>\n\t\t\t\t\twriteFile(\n\t\t\t\t\t\tpartitionCfgAbsPath,\n\t\t\t\t\t\ttoPartitionCfg(\n\t\t\t\t\t\t\tSanitizedPath.create(relative(partitionDir, partitionDir)),\n\t\t\t\t\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nconst ensurePartitionExists = (args: Opts) =>\n\targs.partition\n\t\t? createPartition(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\targs.projectDir,\n\t\t)\n\t\t: createPartition(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\targs.projectDir,\n\t\t);\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\n\nexport default async (args: RequestArgs.ProxyRequestArgs) => {\n\tconst opts = args as Opts;\n\n\treturn ensurePartitionExists(opts)\n\t\t.then(configAbsPath => {\n\t\t\tif (!opts.init) {\n\t\t\t\tconst retval = opts.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', opts.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
1
+ {"version":3,"sources":["index.ts","common.ts","config.ts","contractTestTemplate.ts","proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport { CustomRequestArgs, toRequestArgs } from './common';\nimport createContractTest from './contractTestTemplate';\nimport proxy from './proxy';\n\nPlugin.create<CustomRequestArgs>(requestArgs => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract-test',\n\t\t\tcommand: 'contract-test <michelsonArtifact>',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'michelsonArtifact',\n\t\t\t\t\tdescription: 'Name of the michelson contract (artifact) to generate tests for',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'partition',\n\t\t\t\t\tdescription: 'Partition to place generated test suite',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,\n\t\t\t\t}),\n\t\t\t],\n\t\t\tdescription: 'Generate integration test for a contract',\n\t\t\thandler: createContractTest,\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { LoadedConfig, RequestArgs, SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\nimport * as JestConfig from './config';\n\nexport type DefaultConfig = typeof defaults;\n\nexport interface CustomRequestArgs extends RequestArgs.t {\n\tconfig: JestConfig.t;\n\tpartition?: string;\n\tinit?: string;\n\ttestPattern?: string;\n}\n\nexport const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {\n\tconst config = {\n\t\tjest: {\n\t\t\ttestsRootDir: 'tests',\n\t\t},\n\t\t...args.config,\n\t};\n\n\treturn {\n\t\t...args,\n\t\tconfig: JestConfig.create(config),\n\t};\n};\n\nexport const getDefaultConfig = (defaultConfig: DefaultConfig) => {\n\tconst settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };\n\treturn (\n\t\t`\nmodule.exports = ${JSON.stringify(settings, null, 4)}\n`\n\t);\n};\n\nexport const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nexport const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nexport const getTestsRootDir = (config: JestConfig.t) => {\n\treturn config.jest.testsRootDir;\n};\n\nexport const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nexport const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nexport const getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nexport const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) =>\n\twriteFile(\n\t\tgetPartitionConfigAbspath(partitionDir),\n\t\ttoPartitionCfg(\n\t\t\tSanitizedPath.create(relative(partitionDir, partitionDir)),\n\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t),\n\t);\n\nexport const ensurePartitionExists = async (\n\tpartitionDir: SanitizedAbsPath.t,\n\tprojectDir: SanitizedAbsPath.t,\n\tforceCreate = false,\n) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)\n\t\t\t\t.catch(_ => initPartition(partitionDir, projectDir))\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nexport const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>\n\targs.partition\n\t\t? ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\targs.projectDir,\n\t\t\tforceCreate,\n\t\t)\n\t\t: ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\targs.projectDir,\n\t\t\tforceCreate,\n\t\t);\n","import { LoadedConfig } from '@taqueria/node-sdk';\nimport { z } from 'zod';\n\nconst jestType: unique symbol = Symbol('jestConfig');\n\nconst rawSchema = LoadedConfig.rawSchema.extend({\n\tjest: z.preprocess(\n\t\tinput => {\n\t\t\tconst overrides = typeof input === 'object'\n\t\t\t\t? input\n\t\t\t\t: {};\n\n\t\t\treturn {\n\t\t\t\t'testsRootDir': 'tests',\n\t\t\t\t...overrides,\n\t\t\t};\n\t\t},\n\t\tz.object({\n\t\t\t'testsRootDir': z.preprocess(\n\t\t\t\tval => val ?? 'tests',\n\t\t\t\tz.string().min(1).describe('testsRootDir'),\n\t\t\t),\n\t\t}),\n\t),\n});\n\nconst internalSchema = Object.assign({}, rawSchema);\n\ntype RawInput = z.infer<typeof rawSchema>;\n\ntype Input = z.infer<typeof internalSchema>;\n\nexport interface JestRawConfig extends LoadedConfig.t {\n\t[jestType]: void;\n}\n\nexport type JestConfig = Input & JestRawConfig;\n\nexport type t = JestConfig;\n\nexport const schema = internalSchema.transform(val => val as JestConfig);\n\nexport const create = (input: RawInput | unknown) => {\n\ttry {\n\t\tconst retval = schema.parse(input);\n\t\treturn retval;\n\t} catch {\n\t\tthrow `The .taq/config.json file is invalid.`;\n\t}\n};\n","// import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';\nimport { sendAsyncRes } from '@taqueria/node-sdk';\nimport { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';\nimport {\n\tcreateTestingCodeGenerator,\n\tnormalizeContractName,\n} from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';\nimport { readFile, stat, writeFile } from 'fs/promises';\nimport { basename, dirname, join } from 'path';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';\n\ntype Generator = ReturnType<typeof createTestingCodeGenerator>;\n\ninterface Opts extends CustomRequestArgs {\n\treadonly michelsonArtifact: string;\n\treadonly partition?: string;\n\treadonly name?: string;\n}\n\nconst getMichelsonAbspath = (parsedArgs: Opts) => join(parsedArgs.config.artifactsDir, parsedArgs.michelsonArtifact);\n\nconst ensureMichelsonExists = (parsedArgs: Opts) => {\n\tconst abspath = getMichelsonAbspath(parsedArgs);\n\treturn stat(abspath)\n\t\t.then(() => parsedArgs)\n\t\t.catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run \"taq compile\"?`));\n};\n\nconst getPartition = (parsedArgs: Opts) => {\n\tconst partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);\n\treturn getPartitionAbspath(partition);\n};\n\nconst getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');\n\nconst generateContractTypes = (parsedArgs: Opts) =>\n\tgenerateContractTypesProcessContractFiles({\n\t\tinputTzContractDirectory: parsedArgs.config.artifactsDir,\n\t\tinputFiles: [getMichelsonAbspath(parsedArgs)],\n\t\toutputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),\n\t\tformat: 'tz',\n\t\ttypeAliasMode: 'file',\n\t}).then(_ => parsedArgs);\n\nconst getContractName = (parsedArgs: Opts) =>\n\tparsedArgs.name\n\t\t? parsedArgs.name.trim().replace(/\\.ts$/, '')\n\t\t: basename(parsedArgs.michelsonArtifact, '.tz');\n\nconst generateTestSuite = (parsedArgs: Opts) => {\n\tconst michelsonAbspath = getMichelsonAbspath(parsedArgs);\n\tconst contractName = getContractName(parsedArgs);\n\tconst partition = getPartition(parsedArgs);\n\tconst jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);\n\n\treturn readFile(michelsonAbspath, { encoding: 'utf-8' })\n\t\t.then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))\n\t\t.then(createTestingCodeGenerator)\n\t\t.then(toJest(contractName))\n\t\t.then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))\n\t\t.then(() => jestSuiteAbspath);\n};\n\nconst toJest = (contractName: string) =>\n\t(generator: Generator) => {\n\t\tconst methodCalls = generator.methods.map(m => ({\n\t\t\tname: m.name,\n\t\t\tmethodCall: generator.generateMethodCall({\n\t\t\t\tmethodName: m.name,\n\t\t\t\tformatting: {\n\t\t\t\t\tindent: 2,\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstorageAccess: generator.generateStorageAccess({ storagePath: '' }),\n\t\t}));\n\t\treturn `\nimport { TezosToolkit } from '@taquito/taquito';\nimport { char2Bytes } from '@taquito/utils';\nimport { tas } from './types/type-aliases';\nimport { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';\nimport { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';\n\ndescribe('${contractName}', () => {\n const Tezos = new TezosToolkit('RPC_URL');\n let contract: ContractType = undefined as unknown as ContractType;\n beforeAll(async () => {\n ${generator.generateOrigination({ formatting: { indent: 3 } }).code}\n });\n\n${\n\t\t\tmethodCalls.map(x => `\n it('should call ${x.name}', async () => {\n ${x.storageAccess.getStorageValueFunctionCode}\n const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();\n ${x.methodCall.code}\n const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();\n\n expect(storageValueAfter).toBe('');\n });\n`).join('')\n\t\t});\n`;\n\t};\n\nexport default (parsedArgs: Opts) => {\n\treturn ensureMichelsonExists(parsedArgs)\n\t\t.then(ensureSelectedPartitionExists)\n\t\t.then(() => parsedArgs)\n\t\t.then(generateContractTypes)\n\t\t.then(generateTestSuite)\n\t\t.then(outFile => sendAsyncRes(`Test suite generated: ${outFile}`));\n};\n","import { sendAsyncRes } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { execa } from 'execa';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\nexport default async (args: RequestArgs.t) => {\n\tconst parsedArgs = toRequestArgs(args);\n\treturn ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)\n\t\t.then(configAbsPath => {\n\t\t\tif (!parsedArgs.init) {\n\t\t\t\tconst retval = parsedArgs.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],"mappings":";AAAA,SAAS,QAAQ,QAAQ,eAAe,MAAM,gBAAgB;;;ACA9D,SAAe,oBAAkC;AACjD,SAAoC,kBAAkB,qBAAqB;AAC3E,SAAS,OAAO,MAAM,iBAAiB;AACvC,SAAS,gBAAgB;AACzB,SAAS,MAAM,gBAAgB;;;ACJ/B,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,IAAM,WAA0B,OAAO,YAAY;AAEnD,IAAM,YAAY,aAAa,UAAU,OAAO;AAAA,EAC/C,MAAM,E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ACd,CAAC;AAAA,MACF;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACV,SAAS,OAAO;AAAA,MACf,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,cAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,UAAU;AAAA,UACV,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,OAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,MAAM;AAAA,UACN,cAAc,cAAc,WAAW,EAAE,OAAO,KAAK;AAAA,QACtD,CAAC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,SAAS;AAAA,IACV,CAAC;AAAA,EACF;AAAA,EACA;AACD,IAAI,QAAQ,IAAI;","names":["sendAsyncRes","stat","writeFile","join","join","stat","writeFile","sendAsyncRes","sendAsyncRes","sendAsyncRes"]}
package/index.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { Option, Plugin, PositionalArg, Task } from '@taqueria/node-sdk';
1
+ import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';
2
+ import { CustomRequestArgs, toRequestArgs } from './common';
3
+ import createContractTest from './contractTestTemplate';
2
4
  import proxy from './proxy';
3
5
 
4
- Plugin.create(() => ({
6
+ Plugin.create<CustomRequestArgs>(requestArgs => ({
5
7
  schema: '0.1',
6
8
  version: '0.4.0',
7
9
  alias: 'jest',
@@ -35,5 +37,29 @@ Plugin.create(() => ({
35
37
  ],
36
38
  }),
37
39
  ],
40
+ templates: [
41
+ Template.create({
42
+ template: 'contract-test',
43
+ command: 'contract-test <michelsonArtifact>',
44
+ positionals: [
45
+ PositionalArg.create({
46
+ placeholder: 'michelsonArtifact',
47
+ description: 'Name of the michelson contract (artifact) to generate tests for',
48
+ required: true,
49
+ type: 'string',
50
+ }),
51
+ ],
52
+ options: [
53
+ Option.create({
54
+ flag: 'partition',
55
+ description: 'Partition to place generated test suite',
56
+ type: 'string',
57
+ defaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,
58
+ }),
59
+ ],
60
+ description: 'Generate integration test for a contract',
61
+ handler: createContractTest,
62
+ }),
63
+ ],
38
64
  proxy,
39
65
  }), process.argv);
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@taqueria/plugin-jest",
3
- "version": "0.8.4",
3
+ "version": "0.10.0",
4
+ "main": "index.cjs",
5
+ "module": "index.js",
6
+ "source": "index.ts",
7
+ "type": "module",
4
8
  "description": "A plugin for Taqueria providing automated testing using the Jest Testing Framework",
5
9
  "keywords": [
6
10
  "taqueria",
@@ -12,39 +16,46 @@
12
16
  "ecadlabs",
13
17
  "tezos"
14
18
  ],
15
- "targets": {
16
- "default": {
17
- "source": "./index.ts",
18
- "distDir": "./",
19
- "context": "node",
20
- "isLibrary": true,
21
- "outputFormat": "esmodule"
22
- }
23
- },
24
19
  "scripts": {
25
- "build": "npx tsc -noEmit -p ./tsconfig.json && npx parcel build --no-cache 2>&1"
20
+ "build": "npx tsc -noEmit -p ./tsconfig.json && npx tsup"
26
21
  },
27
22
  "author": "ECAD Labs",
28
23
  "license": "Apache-2.0",
29
- "type": "module",
30
24
  "repository": {
31
25
  "type": "git",
32
26
  "url": "https://github.com/ecadlabs/taqueria.git",
33
27
  "directory": "taqueria-plugin-jest"
34
28
  },
35
29
  "dependencies": {
36
- "@taqueria/node-sdk": "^0.8.4",
30
+ "@taqueria/node-sdk": "^0.10.0",
31
+ "@taqueria/plugin-contract-types": "^0.10.0",
37
32
  "async-retry": "^1.3.3",
38
33
  "execa": "^6.1.0",
39
34
  "fast-glob": "^3.2.7",
40
- "jest": "^28.1.0",
41
- "jest-cli": "^28.1.0",
42
35
  "jest-config": "^28.1.0"
43
36
  },
44
37
  "devDependencies": {
45
38
  "@types/async-retry": "^1.3.3",
46
39
  "@types/jest": "^27.5.1",
47
- "parcel": "2.6.1",
48
- "typescript": "4.7.2"
40
+ "tsup": "^6.1.3",
41
+ "typescript": "4.7.2",
42
+ "jest": "^28.1.0",
43
+ "jest-cli": "^28.1.0"
44
+ },
45
+ "tsup": {
46
+ "entry": [
47
+ "index.ts"
48
+ ],
49
+ "sourcemap": true,
50
+ "target": "node16",
51
+ "outDir": "./",
52
+ "dts": true,
53
+ "clean": false,
54
+ "skipNodeModulesBundle": true,
55
+ "platform": "node",
56
+ "format": [
57
+ "esm",
58
+ "cjs"
59
+ ]
49
60
  }
50
61
  }
package/proxy.ts CHANGED
@@ -1,95 +1,7 @@
1
- import { noop, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';
2
- import { LoadedConfig, RequestArgs, SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';
1
+ import { sendAsyncRes } from '@taqueria/node-sdk';
2
+ import { RequestArgs } from '@taqueria/node-sdk/types';
3
3
  import { execa } from 'execa';
4
- import { mkdir, stat, writeFile } from 'fs/promises';
5
- import { defaults } from 'jest-config';
6
- import { join, relative } from 'path';
7
-
8
- type DefaultConfig = typeof defaults;
9
-
10
- interface CustomConfig extends LoadedConfig.t {
11
- readonly jestTestsRootDir?: string;
12
- }
13
-
14
- interface Opts extends RequestArgs.ProxyRequestArgs {
15
- readonly config: CustomConfig;
16
- readonly init: boolean;
17
- readonly partition: string;
18
- readonly testPattern: string;
19
- }
20
-
21
- const getDefaultConfig = (defaultConfig: DefaultConfig) => `
22
- module.exports = ${JSON.stringify(defaults, null, 4)}
23
- `;
24
-
25
- const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {
26
- const jestRootConfig = getRootConfigAbspath(projectDir);
27
- return stat(jestRootConfig)
28
- .catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))
29
- .then(_ => jestRootConfig);
30
- };
31
-
32
- const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>
33
- SanitizedAbsPath.create(
34
- join(projectDir, '.taq', 'jest.config.js'),
35
- );
36
-
37
- const getTestsRootDir = (config: CustomConfig) => {
38
- return config.jestTestsRootDir || 'tests';
39
- };
40
-
41
- const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `
42
- const parentConfig = require('${rootConfigRelPath}')
43
-
44
- module.exports = {
45
- ...parentConfig,
46
- roots: [
47
- "${partitionRelpath}"
48
- ]
49
- }
50
- `;
51
-
52
- const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);
53
-
54
- const getPartitionConfigAbspath = (partitionDir: string) =>
55
- SanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));
56
-
57
- const createPartition = async (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) =>
58
- ensureRootConfigExists(projectDir)
59
- .then(_ => stat(partitionDir))
60
- .then(stats =>
61
- stats.isFile()
62
- ? sendAsyncErr(`${partitionDir} is an invalid partition directory`)
63
- : stats
64
- )
65
- .catch(_ => mkdir(partitionDir, { recursive: true }))
66
- .then(_ => getPartitionConfigAbspath(partitionDir))
67
- .then(partitionCfgAbsPath =>
68
- stat(partitionCfgAbsPath)
69
- .catch(_ =>
70
- writeFile(
71
- partitionCfgAbsPath,
72
- toPartitionCfg(
73
- SanitizedPath.create(relative(partitionDir, partitionDir)),
74
- SanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),
75
- ),
76
- )
77
- )
78
- )
79
- .then(_ => getPartitionConfigAbspath(partitionDir));
80
-
81
- const ensurePartitionExists = (args: Opts) =>
82
- args.partition
83
- ? createPartition(
84
- SanitizedAbsPath.create(join(args.projectDir, args.partition)),
85
- args.projectDir,
86
- )
87
- : createPartition(
88
- SanitizedAbsPath.create(
89
- join(args.projectDir, getTestsRootDir(args.config)),
90
- ),
91
- args.projectDir,
92
- );
4
+ import { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';
93
5
 
94
6
  const execCmd = (cmd: string, args: string[]) => {
95
7
  const child = execa(cmd, args, {
@@ -103,15 +15,13 @@ const execCmd = (cmd: string, args: string[]) => {
103
15
 
104
16
  return child;
105
17
  };
106
-
107
- export default async (args: RequestArgs.ProxyRequestArgs) => {
108
- const opts = args as Opts;
109
-
110
- return ensurePartitionExists(opts)
18
+ export default async (args: RequestArgs.t) => {
19
+ const parsedArgs = toRequestArgs(args);
20
+ return ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)
111
21
  .then(configAbsPath => {
112
- if (!opts.init) {
113
- const retval = opts.testPattern
114
- ? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', opts.testPattern])
22
+ if (!parsedArgs.init) {
23
+ const retval = parsedArgs.testPattern
24
+ ? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])
115
25
  : execCmd('npx', ['jest', '-c', configAbsPath]);
116
26
  return retval.then(child => {
117
27
  if (child.exitCode === 0) return;
package/tsconfig.json CHANGED
@@ -31,7 +31,10 @@
31
31
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
32
32
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
33
33
  // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
34
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
34
+ "types": [
35
+ "node",
36
+ "jest"
37
+ ], /* Specify type package names to be included without being referenced in a source file. */
35
38
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
39
  // "resolveJsonModule": true, /* Enable importing .json files */
37
40
  // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
@@ -68,13 +71,13 @@
68
71
 
69
72
  /* Interop Constraints */
70
73
  "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
71
- "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
72
75
  "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
73
76
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
77
  "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
75
78
 
76
79
  /* Type Checking */
77
- "strict": true, /* Enable all strict type-checking options. */
80
+ "strict": true /* Enable all strict type-checking options. */
78
81
  // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79
82
  // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80
83
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
@@ -96,6 +99,6 @@
96
99
 
97
100
  /* Completeness */
98
101
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
102
+ // "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
103
  }
101
104
  }