-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get the plugin working with Typescript #72
Comments
So in my case I am using a dist file for the transpiled javascript and pointing my cypress.json to the specific folders for plugins and support. That way I cheated and did this // tslint:disable-next-line:no-var-requires
const command = require('cypress-image-snapshot/command')
command.addMatchImageSnapshotCommand({
customDiffConfig: {threshold: 5.0}, // threshold for each pixel
failureThreshold: 5.0, // threshold for entire image
failureThresholdType: 'percent', // percent of image or number of pixels
}); And it doesn't pop an error during transpile. |
I had the same problems and found a solution.
You need to add a custom module definition file for that.
Currently there's an issue with the typescript preprocessor that causes this behavior: nrwl/nx#1609. As a workaround you can declare a type for The following setup worked for me:
import '../support';
describe('signin page', () => {
beforeEach(() => {
cy.visit('/signin');
});
it('should match the design', () => {
cy.matchImageSnapshot();
});
});
import './commands';
import { addMatchImageSnapshotCommand, SnapshotOptions } from 'cypress-image-snapshot/command';
addMatchImageSnapshotCommand();
declare global {
namespace Cypress {
interface Chainable {
/**
* Screenshot test the current page.
* @param name file name of the screenshot
* @param options general options
*/
matchImageSnapshot(name: string, options?: SnapshotOptions): Chainable<Element>;
/**
* Screenshot test the current page.
* @param options general options
*/
matchImageSnapshot(options?: SnapshotOptions): Chainable<Element>;
}
}
}
declare module 'cypress-image-snapshot/command' {
type SnapshotOptions = Partial<
Cypress.Loggable &
Cypress.Timeoutable &
Cypress.ScreenshotOptions &
import('jest-image-snapshot').MatchImageSnapshotOptions
>;
export const addMatchImageSnapshotCommand: (options?: SnapshotOptions) => void;
} |
I went ahead and added typings for folks to use: DefinitelyTyped/DefinitelyTyped#41222 Now, all you need to do is |
should issue be closed? also, adding |
@Keysox |
Hi,
I already worked through the suggestions in #13 however I still can't get the plugin working.
We are using TypeScript with WebPack.
I also installed @types/jest-image-snapshot
I've added a file index.d.ts in my <"root dir">/types/cypress-image-snapshot folder:
index.d.ts:
Then pointing to the file in tsconfig.json:
tsconfig.json
In <"rootDir">/cypress/plugins/index.js I added the required lines for this plugin:
So far so good, but when I add in /cypress/support/commands.ts (not commands.js) :
I get an error saying that no declaration for the module "../../node_modules/cypress-image-snapshot/command" could be found and I should try to install @types/cypress-image-snapshot (which does not exist) or that I should add a declaration file (.d.ts), which contains "declare module 'cypress-image-snapshot';"
And in my test specs I can add a cy.matchImageSnapshot command and I do not get a syntax-error in the spec, but when I run cypress I get an error:
TypeError: cy.matchImageSnapshot is not a function
The text was updated successfully, but these errors were encountered: