Skip to content

Commit

Permalink
fix(utils): intellisense on matchScreenshot command (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored May 26, 2023
1 parent 8fb87a0 commit d1c2d5b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
utils/types/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dist
!action/dist

# utils
utils/types/
utils/commands.js

# misc
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
utils/types/
node_modules/
9 changes: 8 additions & 1 deletion utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { baseExists, compareScreenshots, onAfterScreenshot } from './screenshots';
import { MatchScreenshotArgs } from './match-screenshot';

export function setupVisualTests(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) {
on('after:screenshot', onAfterScreenshot);
Expand All @@ -14,4 +15,10 @@ export function setupVisualTests(on: Cypress.PluginEvents, config: Cypress.Plugi
return config;
}

export { matchScreenshot } from './match-screenshot';
declare global {
namespace Cypress {
interface Chainable {
matchScreenshot(args?: MatchScreenshotArgs): Chainable;
}
}
}
11 changes: 0 additions & 11 deletions utils/match-screenshot-command.ts

This file was deleted.

2 changes: 2 additions & 0 deletions utils/match-screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ export function matchScreenshot(subject: Cypress.JQueryWithSelector | Window | D
return null;
});
}

Cypress.Commands.add('matchScreenshot', { prevSubject: ['optional', 'element', 'window', 'document'] }, matchScreenshot);
8 changes: 5 additions & 3 deletions utils/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "comparadise-utils",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "types/index.d.ts",
"license": "Apache-2.0",
"files": [
"dist",
"types",
"commands.js"
],
"repository": {
Expand All @@ -26,7 +27,8 @@
"@types/pngjs": "6.0.1"
},
"scripts": {
"build": "tsc",
"postbuild": "echo \"require('./dist/match-screenshot-command');\" > commands.js"
"prebuild": "rm -rf dist types",
"build": "tsc && tsc --project tsconfig.types.json",
"postbuild": "echo \"require('./dist/match-screenshot');\" > commands.js && echo \"export {};\" > types/index.js"
}
}
2 changes: 1 addition & 1 deletion utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declaration": false,
"types": ["cypress"],
"noEmit": false,
"sourceMap": false,
Expand Down
12 changes: 12 additions & 0 deletions utils/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"types": ["cypress"],
"noEmit": false,
"outDir": "types"
},
"include": ["**/*.ts"],
"exclude": ["dist", "node_modules"]
}

0 comments on commit d1c2d5b

Please sign in to comment.