Browse Source

get relative path in cypress tests with path-browserify

Yuki Takei 2 years ago
parent
commit
f5193d0bd8

+ 3 - 1
apps/app/test/cypress/e2e/23-editor/23-editor--with-navigation.cy.ts

@@ -1,3 +1,5 @@
+import path from 'path-browserify';
+
 function openEditor() {
 function openEditor() {
   cy.get('#grw-page-editor-mode-manager').as('pageEditorModeManager').should('be.visible');
   cy.get('#grw-page-editor-mode-manager').as('pageEditorModeManager').should('be.visible');
   cy.waitUntil(() => {
   cy.waitUntil(() => {
@@ -59,7 +61,7 @@ context('Editor while uploading to a new page', () => {
     cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-2`);
     cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-2`);
 
 
     // drag-drop a file
     // drag-drop a file
-    const filePath = 'test/cypress/integration/23-editor/assets/example.txt';
+    const filePath = path.relative('/', path.resolve(Cypress.spec.relative, '../assets/example.txt'));
     cy.get('.dropzone').selectFile(filePath, { action: 'drag-drop' });
     cy.get('.dropzone').selectFile(filePath, { action: 'drag-drop' });
 
 
     // expect
     // expect

+ 2 - 0
package.json

@@ -61,6 +61,7 @@
     "@types/eslint": "^8.37.0",
     "@types/eslint": "^8.37.0",
     "@types/estree": "^1.0.1",
     "@types/estree": "^1.0.1",
     "@types/node": "^17.0.43",
     "@types/node": "^17.0.43",
+    "@types/path-browserify": "^1.0.0",
     "@types/rewire": "^2.5.28",
     "@types/rewire": "^2.5.28",
     "@typescript-eslint/eslint-plugin": "^5.59.7",
     "@typescript-eslint/eslint-plugin": "^5.59.7",
     "@typescript-eslint/parser": "^5.59.7",
     "@typescript-eslint/parser": "^5.59.7",
@@ -80,6 +81,7 @@
     "eslint-plugin-vitest": "^0.2.3",
     "eslint-plugin-vitest": "^0.2.3",
     "glob": "^8.1.0",
     "glob": "^8.1.0",
     "mock-require": "^3.0.3",
     "mock-require": "^3.0.3",
+    "path-browserify": "^1.0.1",
     "postcss": "^8.4.5",
     "postcss": "^8.4.5",
     "postcss-scss": "^4.0.3",
     "postcss-scss": "^4.0.3",
     "reg-keygen-git-hash-plugin": "^0.11.1",
     "reg-keygen-git-hash-plugin": "^0.11.1",

+ 5 - 0
yarn.lock

@@ -3974,6 +3974,11 @@
   resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.3.tgz#705bb349e789efa06f43f128cef51240753424cb"
   resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.3.tgz#705bb349e789efa06f43f128cef51240753424cb"
   integrity sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==
   integrity sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==
 
 
+"@types/path-browserify@^1.0.0":
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/@types/path-browserify/-/path-browserify-1.0.0.tgz#294ec6e88b6b0d340a3897b7120e5b393f16690e"
+  integrity sha512-XMCcyhSvxcch8b7rZAtFAaierBYdeHXVvg2iYnxOV0MCQHmPuRRmGZPFDRzPayxcGiiSL1Te9UIO+f3cuj0tfw==
+
 "@types/pixelmatch@^5.2.2":
 "@types/pixelmatch@^5.2.2":
   version "5.2.4"
   version "5.2.4"
   resolved "https://registry.yarnpkg.com/@types/pixelmatch/-/pixelmatch-5.2.4.tgz#ca145cc5ede1388c71c68edf2d1f5190e5ddd0f6"
   resolved "https://registry.yarnpkg.com/@types/pixelmatch/-/pixelmatch-5.2.4.tgz#ca145cc5ede1388c71c68edf2d1f5190e5ddd0f6"