Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/build-rs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from "path";
jest.setTimeout(1200000);

describe("e2e tests for build command", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/build-cmd/rust");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/wasm/rust");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p1/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options:
-h, --help display help for command
`;

const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/deploy");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "deploy");
const testCases =
fs.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
99 changes: 99 additions & 0 deletions packages/cli/src/__tests__/e2e/p2/build.interface.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { clearStyle, polywrapCli } from "../utils";
import { testBuildOutput } from "../helpers/testBuildOutput";
import { BuildCommandOptions } from "../../../commands";

import { GetPathToCliTestFiles } from "@polywrap/test-cases";
import { Commands } from "@polywrap/cli-js";
import fs from "fs";
import path from "path";

jest.setTimeout(500000);

describe("e2e tests for interface build command", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/interface");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

const getTestCaseDir = (index: number) =>
path.join(testCaseRoot, testCases[index]);

const testCliOutput = (
testCaseDir: string,
exitCode: number,
stdout: string,
stder: string
) => {
const output = clearStyle(stdout);
const error = clearStyle(stder);

const expected = JSON.parse(
fs.readFileSync(
path.join(testCaseDir, "expected", "stdout.json"),
"utf-8"
)
);

if (expected.stdout) {
if (Array.isArray(expected.stdout)) {
for (const line of expected.stdout) {
expect(output).toContain(line);
}
} else {
expect(output).toContain(expected.stdout);
}
}

if (expected.stderr) {
if (Array.isArray(expected.stderr)) {
for (const line of expected.stderr) {
expect(error).toContain(line);
}
} else {
expect(error).toContain(expected.stderr);
}
}

if (expected.exitCode) {
expect(exitCode).toEqual(expected.exitCode);
}

if (expected.files) {
for (const file of expected.files) {
expect(fs.existsSync(path.join(testCaseDir, file))).toBeTruthy();
}
}
};

describe("test-cases", () => {
for (let i = 0; i < testCases.length; i++) {
const testCaseName = testCases[i];
const testCaseDir = getTestCaseDir(i);

let args: BuildCommandOptions;
let cmdFile = path.join(testCaseDir, "cmd.json");
if (fs.existsSync(cmdFile)) {
const cmdConfig = JSON.parse(fs.readFileSync(cmdFile, "utf-8"));
if (cmdConfig) {
args = cmdConfig;
}
}

test(testCaseName, async () => {
const { exitCode, stdout, stderr } = await Commands.build({
...args,
verbose: true
}, {
cwd: testCaseDir,
cli: polywrapCli,
});

const buildDir = path.join(testCaseDir, "build");

testCliOutput(testCaseDir, exitCode, stdout, stderr);
testBuildOutput(testCaseDir, buildDir);
});
}
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p2/build.plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { testBuildOutput } from "../helpers/testBuildOutput";
import { BuildCommandOptions } from "../../../commands";

describe("e2e tests for build command - plugin project", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "plugin/build-cmd");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/plugin");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p2/build.wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Options:
jest.setTimeout(500000);

describe("e2e tests for build command", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p2/codegen.app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from "path";
import fs from "fs";

describe("e2e tests for codegen command - app project", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "app", "codegen");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "codegen/app");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p2/codegen.plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import path from "path";
import fs from "fs";

describe("e2e tests for codegen command - plugin project", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "plugin/codegen");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "codegen/plugin");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p2/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Options:
`;

describe("e2e tests for codegen command", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/codegen");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "codegen/wasm");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/p2/codegen.wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { testCodegenOutput } from "../helpers/testCodegenOutput";
import { CodegenCommandOptions } from "../../../commands";

describe("e2e tests for codegen command - wasm/interface project", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/codegen");
const testCaseRoot = path.join(GetPathToCliTestFiles(), "codegen/wasm");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/unit/docker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("e2e tests for docker", () => {
await Commands.infra("down", {
modules: ["eth-ens-ipfs"]
}, {
cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"),
cwd: path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript/001-sanity"),
cli: polywrapCli,
env: process.env as Record<string, string>
});
Expand All @@ -18,7 +18,7 @@ describe("e2e tests for docker", () => {
await Commands.infra("down", {
modules: ["eth-ens-ipfs"]
}, {
cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"),
cwd: path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript/001-sanity"),
cli: polywrapCli,
env: process.env as Record<string, string>
});
Expand All @@ -31,7 +31,7 @@ describe("e2e tests for docker", () => {
strategy: "image",
verbose: true,
}, {
cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"),
cwd: path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript/001-sanity"),
cli: polywrapCli
}).then((result: { exitCode: number; stdout: string; stderr: string }) => {
const { exitCode, stderr } = result;
Expand Down
22 changes: 16 additions & 6 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SupportedStrategies,
DockerImageBuildStrategy,
LocalBuildStrategy,
NoopBuildStrategy,
} from "../lib/build-strategies";
import { DEFAULT_CODEGEN_DIR } from "../lib/defaults";
import { watchProject } from "../lib/watchProject";
Expand Down Expand Up @@ -211,13 +212,22 @@ async function run(options: Required<BuildCommandOptions>) {
if (isPolywrapManifestLanguage(language)) {
await validateManifestModules(manifest as PolywrapManifest);

buildStrategy = createBuildStrategy(
strategy,
outputDir,
project as PolywrapProject
);
const isInterface = language === "interface";

if (isInterface) {
buildStrategy = new NoopBuildStrategy({
project: project as PolywrapProject,
outputDir,
});
} else {
buildStrategy = createBuildStrategy(
strategy,
outputDir,
project as PolywrapProject
);
}

canRunCodegen = language !== "interface";
canRunCodegen = !isInterface;
}

const execute = async (): Promise<boolean> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BuildStrategy } from "../BuildStrategy";

export class NoopBuildStrategy extends BuildStrategy<void> {
getStrategyName(): string {
return "noop";
}

buildSources(): Promise<void> {
return Promise.resolve();
}

async build(): Promise<void> {
return Promise.resolve();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./DockerVMStrategy";
export * from "./LocalStrategy";
export * from "./DockerImageStrategy";
export * from "./NoopStrategy";
6 changes: 3 additions & 3 deletions packages/js/cli/src/__tests__/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const clearDir = (dir: string) => {
const testData: CommandTestCaseData<CommandTypings> = {
build: [{
options: { strategy: "vm" },
cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"),
cwd: path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript/001-sanity"),
before: async (test) => {
// clear build dir
if (!test.cwd) throw Error("This shouldn't happen");
Expand All @@ -72,7 +72,7 @@ const testData: CommandTestCaseData<CommandTypings> = {
}],
codegen: [{
options: { codegenDir: "./test" },
cwd: path.join(GetPathToCliTestFiles(), "wasm/codegen/001-sanity-assemblyscript"),
cwd: path.join(GetPathToCliTestFiles(), "codegen/wasm/001-sanity-assemblyscript"),
before: (test) => {
// clear build dir
if (!test.cwd || !test.options?.codegenDir)
Expand Down Expand Up @@ -144,7 +144,7 @@ const testData: CommandTestCaseData<CommandTypings> = {
}]
},
deploy: [{
cwd: path.join(GetPathToCliTestFiles(), "wasm/deploy/001-sanity"),
cwd: path.join(GetPathToCliTestFiles(), "deploy/001-sanity"),
env: {
PATH: process.env.PATH || "",
IPFS_GATEWAY_URI: ETH_ENS_IPFS_MODULE_CONSTANTS.ipfsProvider,
Expand Down
2 changes: 1 addition & 1 deletion packages/templates/plugin/python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "templates-plugin-python",
"private": true,
"dependencies": {
"polywrap": "0.10.0-pre.13"
"polywrap": "0.10.0-pre.14"
}
}
2 changes: 1 addition & 1 deletion packages/templates/wasm/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
edition = "2021"

[dependencies]
polywrap-wasm-rs = { version = "0.10.0-pre.13" }
polywrap-wasm-rs = { version = "0.10.0-pre.14" }
serde = { version = "1.0", features = ["derive"] }

[lib]
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
format: 0.2.0
project:
name: Test
type: interface
source:
schema: ./schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type Module {
methodOne(
str: String!
optStr: String
): Object!
}

type Object {
u: UInt!
array: [Boolean!]!
bytes: Bytes
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"stdout": ["Manifest written to ./build/wrap.info"],
"exitCode": 0
}
Loading