@graphprotocol/graph-cli
Version:
CLI for building for and deploying to The Graph
180 lines (179 loc) • 11.7 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const loadManifestUtils = __importStar(require("../migrations/util/load-manifest"));
const graphTsUtil = __importStar(require("../migrations/util/versions"));
const version_1 = require("./version");
vitest_1.describe.concurrent('Version Command Helpers', () => {
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.resetModules();
});
(0, vitest_1.describe)('assertManifestApiVersion', () => {
const fakeManifestPath = 'fake/manifest/path';
const minimumApiVersion = '0.0.5';
(0, vitest_1.describe)('With just dataSources', () => {
(0, vitest_1.test)('When all of them are less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.1' } },
{ mapping: { apiVersion: '0.0.2' } },
{ mapping: { apiVersion: '0.0.3' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
(0, vitest_1.test)('When one of them is less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.2' } },
{ mapping: { apiVersion: '0.0.5' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
(0, vitest_1.test)('When none of them are less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.6' } },
{ mapping: { apiVersion: '0.0.5' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
});
});
(0, vitest_1.describe)('With dataSources and templates', () => {
(0, vitest_1.describe)('And the dataSources have a lower apiVersion', () => {
(0, vitest_1.test)('When all of the templates are less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.3' } },
],
templates: [
{ mapping: { apiVersion: '0.0.1' } },
{ mapping: { apiVersion: '0.0.2' } },
{ mapping: { apiVersion: '0.0.3' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
(0, vitest_1.test)('When one of the templates is less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.3' } },
],
templates: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.2' } },
{ mapping: { apiVersion: '0.0.5' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
(0, vitest_1.test)('When none of the templates are less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.3' } },
],
templates: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.6' } },
{ mapping: { apiVersion: '0.0.5' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
});
(0, vitest_1.describe)('And the dataSources do NOT have a lower apiVersion', () => {
(0, vitest_1.test)('When all of the templates are less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.6' } },
],
templates: [
{ mapping: { apiVersion: '0.0.1' } },
{ mapping: { apiVersion: '0.0.2' } },
{ mapping: { apiVersion: '0.0.3' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
(0, vitest_1.test)('When one of the templates is less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.6' } },
],
templates: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.2' } },
{ mapping: { apiVersion: '0.0.5' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
});
(0, vitest_1.test)('When none of the templates are less than minimum apiVersion', async () => {
vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
dataSources: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.6' } },
],
templates: [
{ mapping: { apiVersion: '0.0.5' } },
{ mapping: { apiVersion: '0.0.6' } },
{ mapping: { apiVersion: '0.0.5' } },
],
}));
await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
});
});
});
});
(0, vitest_1.describe)('assertGraphTsVersion', () => {
const fakeNodeModulesDir = 'fake/path/to/node/modules';
const minimumGraphTsVersion = '0.22.0';
(0, vitest_1.test)("When the installed graph-ts version is less than what's supported", async () => {
vitest_1.vi.spyOn(graphTsUtil, 'getGraphTsVersion').mockImplementation(() => Promise.resolve('0.19.0'));
await (0, vitest_1.expect)((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).rejects.toThrow(new Error(`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`));
});
(0, vitest_1.test)('When the installed graph-ts version is a supported one', async () => {
vitest_1.vi.spyOn(graphTsUtil, 'getGraphTsVersion').mockImplementation(() => Promise.resolve('0.22.0'));
await (0, vitest_1.expect)((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).resolves.toBe(undefined);
});
});
});
;