Hi @bongartz
I’ve experienced that error before, which is why I have separated my storage API code into its own file. See below for how i’ve done it:
fileWhereStorageIs.js
(If we don’t find the key, we initialize it. You could ignore the ‘if’ check and just return storage.get() value)
import {storage} from "@forge/api";
export const getFromStorageAPI = async () => {
let foundData = await storage.get(STORAGEKEY);
if (foundData === undefined) {
await storage.set(STORAGEKEY, DEFAULTVALUE);
foundData = await storage.get(STORAGEKEY);
}
return foundData;
};
Then in the custom Resolver, the storage API function is imported:
CustomSettingsResolver.js:
import { getFromStorageAPI } from "./fileWhereStorageIs";
export class CustomSettingsResolver {
constructor(resolver) {
resolver.define('getSettings', () => {
return getFromStorageAPI();
});
}
}
So you can use the ‘getSettings’ Resolver definition to retrieve the data from Storage API.
To further clarify, the custom resolver CustomSettingsResolver.js
is declared in the PARENT resolver index.js
(see below):
import Resolver from '@forge/resolver';
import React from 'react';
//declare your custom resolver files here
import {CustomSettingsResolver} from "./CustomSettingsResolver";
import {BasicAuthResolver} from "./BasicAuthResolver"; //I Left in a second resolver to show you can have multiple custom resolvers
//Pass Parent resolver into Constructor of your custom resolvers
const resolver = new Resolver();
new CustomSettingsResolver(resolver);
new BasicAuthResolver(resolver);
//You can still use parent resolver definitions
resolver.define('getText', async () => {
return 'parentResolverTest';
});
export const resolverHandler = resolver.getDefinitions();
Hope that helps for StorageAPI.
Regarding Testing, there’s multiple methods of testing. Jest works well enough for simple testing, but if you want e2e testing for synthetic tests, there’s a few available that work with Forge apps (Codecept/Playwright/Cypress (i think cypress works with Forge, but it does have trouble with IFrames)