Skip to content

Commit

Permalink
test: fix external attachments test for win
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Sep 26, 2024
1 parent acd7029 commit 37e2fb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 1 addition & 7 deletions test/_helpers/TestDir.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import assert from 'node:assert/strict';
import path from 'node:path';
import fs from 'node:fs';
import fg from 'fast-glob';
import { fileURLToPath } from 'node:url';
import { expect } from '@playwright/test';

Expand All @@ -20,7 +19,7 @@ export class TestDir {
return this.importMeta.url.split('/').slice(-2)[0];
}

getAbsPath(relativePath) {
getAbsPath(relativePath = '') {
return path.isAbsolute(relativePath)
? relativePath
: fileURLToPath(new URL(relativePath, this.importMeta.url));
Expand All @@ -41,11 +40,6 @@ export class TestDir {
return fs.readFileSync(absPath, 'utf8');
}

getAllFiles(relativePath) {
const absPath = this.getAbsPath(relativePath);
return fg.sync(path.join(absPath, '**')).map((file) => path.relative(absPath, file));
}

expectFileContains(relativePath, substr) {
const substrList = Array.isArray(substr) ? substr : [substr];
const fileContents = this.getFileContents(relativePath);
Expand Down
8 changes: 6 additions & 2 deletions test/reporter-cucumber-ext-attachments/test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, expect, TestDir, execPlaywrightTest } from '../_helpers/index.mjs';
import path from 'node:path';
import fg from 'fast-glob';

const testDir = new TestDir(import.meta);

Expand All @@ -8,6 +9,7 @@ test(testDir.name, async () => {
execPlaywrightTest(testDir.name);

checkHtmlReport();
checkAttachmentFiles();
});

function checkHtmlReport() {
Expand All @@ -18,9 +20,11 @@ function checkHtmlReport() {
expect(html.includes('"fileName":"trace","url":".\\/attachments\\/')).toEqual(true);
expect(html.includes('"fileName":"plain text"}')).toEqual(true);
expect(html.includes('"fileName":"json"}')).toEqual(true);
}

const extensions = testDir
.getAllFiles('actual-reports/attachments')
function checkAttachmentFiles() {
const extensions = fg
.sync('actual-reports/attachments/*', { cwd: path.dirname(testDir.getAbsPath()) })
.map((file) => path.extname(file))
.sort();
expect(extensions).toEqual(['.png', '.png', '.webm', '.zip']);
Expand Down

0 comments on commit 37e2fb4

Please sign in to comment.