Skip to content

Commit

Permalink
Fix tests e2e playwright JS module
Browse files Browse the repository at this point in the history
Introduced by #5362, import of Lizmap JS module could not be done.
So playwright has to be a `module` package, `require` has to be replaced by `import` and `__dirname` defined at each file level if needed.
  • Loading branch information
rldhont committed Feb 6, 2025
1 parent 580eb57 commit 5297343
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/end2end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"name": "test",
"description": "E2E Test Lizmap JavaScript",
"author": "3Liz",
"type": "module",
"license": "ISC"
}
13 changes: 13 additions & 0 deletions tests/end2end/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import { test as setup } from '@playwright/test';
import path from 'path';
import { Page } from '@playwright/test';

/**
* The file directory path
* @var string
* @see https://nodejs.org/docs/latest-v15.x/api/esm.html#esm_no_filename_or_dirname
* @see https://stackoverflow.com/questions/64963450/dirname-is-not-defined
* @see https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
* @example
* import { fileURLToPath } from 'url';
* import { dirname } from 'path';
* const __filename = fileURLToPath(import.meta.url);
* const __dirname = dirname(__filename);
*/
const __dirname = path.resolve(path.dirname(''));

/**
* Performs the authentication steps
Expand Down
16 changes: 16 additions & 0 deletions tests/end2end/playwright/base-layers.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
// @ts-check
import * as path from 'path';
import * as fs from 'fs/promises'
import { fileURLToPath } from 'url';
import { existsSync } from 'node:fs';
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';

const __filename = fileURLToPath(import.meta.url);
/**
* The file directory path
* @var string
* @see https://nodejs.org/docs/latest-v15.x/api/esm.html#esm_no_filename_or_dirname
* @see https://stackoverflow.com/questions/64963450/dirname-is-not-defined
* @see https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
* @example
* import { fileURLToPath } from 'url';
* import { dirname } from 'path';
* const __filename = fileURLToPath(import.meta.url);
* const __dirname = dirname(__filename);
*/
const __dirname = path.dirname(__filename);

// To update OSM and GeoPF tiles in the mock directory
// IMPORTANT, this must not be set to `true` while committing, on GitHub. Set to `false`.
const UPDATE_MOCK_FILES = false;
Expand Down
2 changes: 1 addition & 1 deletion tests/end2end/playwright/draw.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
const { gotoMap, reloadMap } = require('./globals')
import { gotoMap, reloadMap } from './globals';

test.describe('Draw', () => {

Expand Down
2 changes: 1 addition & 1 deletion tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
const { expect } = require('@playwright/test');
import { expect } from '@playwright/test';
import { URLSearchParams } from 'url';

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/end2end/playwright/legend.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import {base64svgLineLayer} from "assets/src/modules/state/SymbologyIcons";
import {base64svgLineLayer} from "./../../../assets/src/modules/state/SymbologyIcons";

test.describe('Legend tests', () => {

Expand Down
14 changes: 14 additions & 0 deletions tests/end2end/playwright/print_in_project_projection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import * as path from 'path';
import { test, expect } from '@playwright/test';
import { gotoMap, expectParametersToContain } from './globals';

/**
* The file directory path
* @var string
* @see https://nodejs.org/docs/latest-v15.x/api/esm.html#esm_no_filename_or_dirname
* @see https://stackoverflow.com/questions/64963450/dirname-is-not-defined
* @see https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
* @example
* import { fileURLToPath } from 'url';
* import { dirname } from 'path';
* const __filename = fileURLToPath(import.meta.url);
* const __dirname = dirname(__filename);
*/
const __dirname = path.resolve(path.dirname(''));

test.describe('Print in project projection', () => {

test.beforeEach(async ({ page }) => {
Expand Down
14 changes: 14 additions & 0 deletions tests/end2end/playwright/webdav-upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import * as path from 'path';
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';

/**
* The file directory path
* @var string
* @see https://nodejs.org/docs/latest-v15.x/api/esm.html#esm_no_filename_or_dirname
* @see https://stackoverflow.com/questions/64963450/dirname-is-not-defined
* @see https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
* @example
* import { fileURLToPath } from 'url';
* import { dirname } from 'path';
* const __filename = fileURLToPath(import.meta.url);
* const __dirname = dirname(__filename);
*/
const __dirname = path.resolve(path.dirname(''));

test.describe('WebDAV Server', () => {
test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=form_upload_webdav';
Expand Down

0 comments on commit 5297343

Please sign in to comment.