@argos-ci/cypress 1.1.2 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/support.d.ts CHANGED
@@ -11,7 +11,14 @@ declare global {
11
11
  * cy.get(".post").argosScreenshot()
12
12
  */
13
13
  argosScreenshot: (name: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions> & {
14
+ /**
15
+ * Viewports to take screenshots of.
16
+ */
14
17
  viewports?: ViewportOption[];
18
+ /**
19
+ * Custom CSS evaluated during the screenshot process.
20
+ */
21
+ argosCSS?: string;
15
22
  }) => Chainable<null>;
16
23
  }
17
24
  }
package/dist/support.mjs CHANGED
@@ -1,19 +1,19 @@
1
1
  import 'cypress-wait-until';
2
2
  import { resolveViewport } from '@argos-ci/browser';
3
+ import { getGlobalFilePath } from '@argos-ci/browser/cypress.cjs';
3
4
  import { getScreenshotName, getMetadataPath } from '@argos-ci/util/browser';
4
5
 
6
+ var version = "1.2.0";
7
+
5
8
  function injectArgos() {
6
- const fileName = typeof require.resolve === "function" ? require.resolve("@argos-ci/browser/global.js") : "node_modules/@argos-ci/browser/dist/global.js";
7
- cy.readFile(fileName).then((source)=>cy.window({
8
- log: false
9
- }).then((window)=>{
9
+ cy.window({
10
+ log: false
11
+ }).then((window)=>{
12
+ if (typeof window.__ARGOS__ !== "undefined") return;
13
+ const fileName = getGlobalFilePath();
14
+ return cy.readFile(fileName).then((source)=>{
10
15
  window.eval(source);
11
- }));
12
- }
13
- function readArgosCypressVersion() {
14
- const fileName = typeof require.resolve === "function" ? require.resolve("@argos-ci/cypress/package.json") : "node_modules/@argos-ci/cypress/package.json";
15
- return cy.readFile(fileName).then((source)=>{
16
- return source.version;
16
+ });
17
17
  });
18
18
  }
19
19
  Cypress.Commands.add("argosScreenshot", {
@@ -23,7 +23,7 @@ Cypress.Commands.add("argosScreenshot", {
23
23
  "window",
24
24
  "document"
25
25
  ]
26
- }, (subject, name, { viewports, ...options } = {})=>{
26
+ }, (subject, name, { viewports, argosCSS, ...options } = {})=>{
27
27
  if (!name) {
28
28
  throw new Error("The `name` argument is required.");
29
29
  }
@@ -36,8 +36,9 @@ Cypress.Commands.add("argosScreenshot", {
36
36
  const fullPage = !options.capture || options.capture === "fullPage";
37
37
  cy.window({
38
38
  log: false
39
- }).then((window)=>window.__ARGOS__.prepareForScreenshot({
40
- fullPage
39
+ }).then((window)=>window.__ARGOS__.setup({
40
+ fullPage,
41
+ argosCSS
41
42
  }));
42
43
  function stabilizeAndScreenshot(name) {
43
44
  cy.waitUntil(()=>cy.window({
@@ -58,47 +59,52 @@ Cypress.Commands.add("argosScreenshot", {
58
59
  }).then((window)=>{
59
60
  const mediaType = window.__ARGOS__.getMediaType();
60
61
  const colorScheme = window.__ARGOS__.getColorScheme();
61
- readArgosCypressVersion().then((argosCypressVersion)=>{
62
- const metadata = {
63
- url: window.location.href,
64
- viewport: {
65
- width: window.innerWidth,
66
- height: window.innerHeight
67
- },
68
- colorScheme,
69
- mediaType,
70
- test: {
71
- title: Cypress.currentTest.title,
72
- titlePath: Cypress.currentTest.titlePath
73
- },
74
- browser: {
75
- name: Cypress.browser.name,
76
- version: Cypress.browser.version
77
- },
78
- automationLibrary: {
79
- name: "cypress",
80
- version: Cypress.version
81
- },
82
- sdk: {
83
- name: "@argos-ci/cypress",
84
- version: argosCypressVersion
85
- }
86
- };
87
- cy.writeFile(getMetadataPath(ref.props.path), JSON.stringify(metadata));
88
- });
62
+ const metadata = {
63
+ url: window.location.href,
64
+ viewport: {
65
+ width: window.innerWidth,
66
+ height: window.innerHeight
67
+ },
68
+ colorScheme,
69
+ mediaType,
70
+ test: {
71
+ title: Cypress.currentTest.title,
72
+ titlePath: Cypress.currentTest.titlePath
73
+ },
74
+ browser: {
75
+ name: Cypress.browser.name,
76
+ version: Cypress.browser.version
77
+ },
78
+ automationLibrary: {
79
+ name: "cypress",
80
+ version: Cypress.version
81
+ },
82
+ sdk: {
83
+ name: "@argos-ci/cypress",
84
+ version
85
+ }
86
+ };
87
+ cy.writeFile(getMetadataPath(ref.props.path), JSON.stringify(metadata));
89
88
  });
90
89
  }
91
- if (!viewports) {
90
+ if (viewports) {
91
+ for (const viewport of viewports){
92
+ const viewportSize = resolveViewport(viewport);
93
+ cy.viewport(viewportSize.width, viewportSize.height);
94
+ stabilizeAndScreenshot(getScreenshotName(name, {
95
+ viewportWidth: viewportSize.width
96
+ }));
97
+ }
98
+ // Restore the original viewport
99
+ cy.viewport(Cypress.config("viewportWidth"), Cypress.config("viewportHeight"));
100
+ } else {
92
101
  stabilizeAndScreenshot(name);
93
- return;
94
102
  }
95
- for (const viewport of viewports){
96
- const viewportSize = resolveViewport(viewport);
97
- cy.viewport(viewportSize.width, viewportSize.height);
98
- stabilizeAndScreenshot(getScreenshotName(name, {
99
- viewportWidth: viewportSize.width
103
+ // Teardown Argos
104
+ cy.window({
105
+ log: false
106
+ }).then((window)=>window.__ARGOS__.teardown({
107
+ fullPage,
108
+ argosCSS
100
109
  }));
101
- }
102
- // Restore the original viewport
103
- cy.viewport(Cypress.config("viewportWidth"), Cypress.config("viewportHeight"));
104
110
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/cypress",
3
3
  "description": "Visual testing solution to avoid visual regression. Cypress commands and utilities for Argos visual testing.",
4
- "version": "1.1.2",
4
+ "version": "1.2.1",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -36,7 +36,7 @@
36
36
  "node": ">=16.0.0"
37
37
  },
38
38
  "dependencies": {
39
- "@argos-ci/browser": "1.1.1",
39
+ "@argos-ci/browser": "1.2.1",
40
40
  "@argos-ci/util": "1.1.0",
41
41
  "cypress-wait-until": "^1.7.2"
42
42
  },
@@ -58,5 +58,5 @@
58
58
  "argos-upload": "pnpm exec argos upload cypress/screenshots --build-name \"argos-cypress-e2e-node-$NODE_VERSION-$OS\"",
59
59
  "e2e": "pnpm run test && pnpm run argos-upload"
60
60
  },
61
- "gitHead": "27c07b619069353c2a8c8c98203b9c27b4e2bed0"
61
+ "gitHead": "ba44d1ef3390ed31192b42acf958bc4eb6138e54"
62
62
  }