Skip to content

Commit

Permalink
run tests on windows (via #1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev committed Sep 16, 2024
1 parent 0045cdd commit 5ee7a1e
Show file tree
Hide file tree
Showing 101 changed files with 807 additions and 370 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,15 @@ jobs:
build:
name: "Build"
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [18, 20]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4

- uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
id: setup-chrome
- run: |
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
${{ steps.setup-chrome.outputs.chrome-path }} --version
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand All @@ -88,7 +81,8 @@ jobs:
run: |
yarn install --immutable --immutable-cache
- run: yarn workspace allure-playwright playwright install chromium --with-deps
- name: "Playwright install chromium"
run: yarn workspace allure-playwright playwright install chromium --with-deps

- name: yarn build
run: |
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 1 addition & 3 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ plugins:

supportedArchitectures:
cpu:
- current
- x64
- arm64
libc:
- current
- glibc
- musl
os:
- current
- darwin
- linux
- win32

yarnPath: .yarn/releases/yarn-4.4.1.cjs
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
extends: ["../../.eslintrc.cjs"],
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json", "./tsconfig.test.json"],
project: ["./tsconfig.json", "./test/tsconfig.json"],
},
overrides: [
{
Expand Down
43 changes: 43 additions & 0 deletions packages/allure-codeceptjs/test/spec/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,49 @@ it("should add package label", async () => {
);
});

it("should not depend on CWD", async () => {
const { tests } = await runCodeceptJsInlineTest(
{
"nested/login.test.js": `
Feature("login-feature");
Scenario("failed-scenario", async ({ I }) => {
I.fail();
});
Scenario("passed-scenario", async ({ I }) => {
I.pass();
});
`,
},
{},
"nested",
);

expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "failed-scenario",
fullName: "nested/login.test.js: login-feature > failed-scenario",
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
},
]),
}),
expect.objectContaining({
name: "passed-scenario",
fullName: "nested/login.test.js: login-feature > passed-scenario",
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
},
]),
}),
]),
);
});

it("should add labels from env variables", async () => {
const { tests } = await runCodeceptJsInlineTest(
{
Expand Down
16 changes: 8 additions & 8 deletions packages/allure-codeceptjs/test/spec/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ it("handles simple scenarios", async () => {
status: Status.PASSED,
name: "logout-scenario1",
fullName: "logout.test.js: logout-feature > logout-scenario1",
testCaseId: "0bf4f9a26f520d0d5c2aa270918dd2bd",
historyId: "0bf4f9a26f520d0d5c2aa270918dd2bd:d41d8cd98f00b204e9800998ecf8427e",
testCaseId: "b1cbd7e3cf91f03aa08b912903a297a0",
historyId: "b1cbd7e3cf91f03aa08b912903a297a0:d41d8cd98f00b204e9800998ecf8427e",
}),

expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "logout-scenario2",
fullName: "logout.test.js: logout-feature > logout-scenario2",
testCaseId: "5607c1c83d9b64861ff559d525106c71",
historyId: "5607c1c83d9b64861ff559d525106c71:d41d8cd98f00b204e9800998ecf8427e",
testCaseId: "cf2fc4ae2f9143145a3ee3bae6dff66b",
historyId: "cf2fc4ae2f9143145a3ee3bae6dff66b:d41d8cd98f00b204e9800998ecf8427e",
}),
expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "login-scenario1",
fullName: "nested/login.test.js: login-feature > login-scenario1",
testCaseId: "b63d78080eb28db70a46f9ecccf81927",
historyId: "b63d78080eb28db70a46f9ecccf81927:d41d8cd98f00b204e9800998ecf8427e",
testCaseId: "157be92d422d04e9b79d6d2fbb5020de",
historyId: "157be92d422d04e9b79d6d2fbb5020de:d41d8cd98f00b204e9800998ecf8427e",
}),
expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "login-scenario2",
fullName: "nested/login.test.js: login-feature > login-scenario2",
testCaseId: "32c25d09db299433cdc0cef7a9254b40",
historyId: "32c25d09db299433cdc0cef7a9254b40:d41d8cd98f00b204e9800998ecf8427e",
testCaseId: "fbb987bcdcd21440bb0a4f4d79711387",
historyId: "fbb987bcdcd21440bb0a4f4d79711387:d41d8cd98f00b204e9800998ecf8427e",
}),
]),
);
Expand Down
8 changes: 8 additions & 0 deletions packages/allure-codeceptjs/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"include": ["./**/*"],
"compilerOptions": {
"noEmit": true,
"emitDeclarationOnly": false
}
}
3 changes: 2 additions & 1 deletion packages/allure-codeceptjs/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MessageReader } from "allure-js-commons/sdk/reporter";
export const runCodeceptJsInlineTest = async (
files: Record<string, string | Buffer>,
env?: Record<string, string>,
cwd?: string,
): Promise<AllureResults> => {
const testFiles = {
// package.json is used to find project root in case of absolute file paths are used
Expand Down Expand Up @@ -47,7 +48,7 @@ export const runCodeceptJsInlineTest = async (
...env,
ALLURE_TEST_MODE: "1",
},
cwd: testDir,
cwd: cwd ? join(testDir, cwd) : testDir,
stdio: "pipe",
});
});
Expand Down
7 changes: 0 additions & 7 deletions packages/allure-codeceptjs/tsconfig.test.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
reporters: ["default", ["allure-vitest/reporter", { resultsDir: "./out/allure-results" }]],
typecheck: {
enabled: true,
tsconfig: "./tsconfig.test.json",
tsconfig: "./test/tsconfig.json",
},
},
});
2 changes: 1 addition & 1 deletion packages/allure-cucumberjs/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
extends: ["../../.eslintrc.cjs"],
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json", "./tsconfig.test.json"],
project: ["./tsconfig.json", "./test/tsconfig.json"],
},
overrides: [
{
Expand Down
5 changes: 4 additions & 1 deletion packages/allure-cucumberjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parseTestPlan } from "allure-js-commons/sdk/reporter";
import { setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
import { AllureCucumberWorld } from "./legacy.js";
import { AllureCucumberTestRuntime } from "./runtime.js";
import { getPosixPathRelativeToProjectRoot } from "./utils.js";

BeforeAll(() => {
setGlobalTestRuntime(new AllureCucumberTestRuntime());
Expand All @@ -15,7 +16,9 @@ Before({ name: "ALLURE_FIXTURE_IGNORE" }, (scenario) => {
return;
}
const pickle = scenario.pickle;
const fullName = `${pickle.uri}#${pickle.name}`;
const posixPath = getPosixPathRelativeToProjectRoot(pickle);

const fullName = `${posixPath}#${pickle.name}`;
const tags = pickle.tags.map((tag) => tag.name);

if (!includedInTestPlan(testPlan, { fullName, tags })) {
Expand Down
7 changes: 5 additions & 2 deletions packages/allure-cucumberjs/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "allure-js-commons/sdk/reporter";
import { AllureCucumberWorld } from "./legacy.js";
import type { AllureCucumberLinkConfig, AllureCucumberReporterConfig, LabelConfig } from "./model.js";
import { getPathRelativeToProjectRoot, getPosixPathRelativeToProjectRoot } from "./utils.js";

export default class AllureCucumberReporter extends Formatter {
private readonly afterHooks: Record<string, TestCaseHookDefinition> = {};
Expand Down Expand Up @@ -237,7 +238,9 @@ export default class AllureCucumberReporter extends Formatter {
const doc = this.documentMap.get(pickle.uri)!;
const [scenarioId] = pickle.astNodeIds;
const scenario = this.scenarioMap.get(scenarioId);
const fullName = `${pickle.uri}#${pickle.name}`;

const posixPath = getPosixPathRelativeToProjectRoot(pickle);
const fullName = `${posixPath}#${pickle.name}`;
const result: Partial<TestResult> = {
name: pickle.name,
description: (scenario?.description || doc?.feature?.description || "").trim(),
Expand All @@ -252,7 +255,7 @@ export default class AllureCucumberReporter extends Formatter {
result.labels!.push(
getLanguageLabel(),
getFrameworkLabel("cucumberjs"),
getPackageLabel(pickle.uri),
getPackageLabel(getPathRelativeToProjectRoot(pickle)),
getHostLabel(),
getThreadLabel(data.workerId),
);
Expand Down
12 changes: 12 additions & 0 deletions packages/allure-cucumberjs/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Pickle } from "@cucumber/messages";
import path from "node:path";
import { getPosixPath, getRelativePath } from "allure-js-commons/sdk/reporter";

export const getPathRelativeToProjectRoot = ({ uri }: Pickle) =>
getRelativePath(
// Pickle.uri is always relative to the CWD when run from the CLI.
// However, it might be absolute if run from code.
path.isAbsolute(uri) ? uri : path.join(process.cwd(), uri),
);

export const getPosixPathRelativeToProjectRoot = (pickle: Pickle) => getPosixPath(getPathRelativeToProjectRoot(pickle));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: simple

Scenario: passed
Given a passed step

Scenario: failed
Given a failed step

Scenario: broken
Given a broken step
46 changes: 42 additions & 4 deletions packages/allure-cucumberjs/test/spec/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ it("should add thread and host labels", async () => {
);
});

it("should add thread package label", async () => {
it("should add package label", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"]);

expect(tests).toEqual(
Expand Down Expand Up @@ -86,10 +86,48 @@ it("should add thread package label", async () => {
);
});

it("should calculate package label in a CWD-independent manner", async () => {
const { tests } = await runCucumberInlineTest(["nested/simple"], ["simple"], { cwd: "features/nested" });

expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "passed",
labels: expect.arrayContaining([
{
name: "package",
value: "features.nested.simple.feature",
},
]),
}),
expect.objectContaining({
name: "failed",
labels: expect.arrayContaining([
{
name: "package",
value: "features.nested.simple.feature",
},
]),
}),
expect.objectContaining({
name: "broken",
labels: expect.arrayContaining([
{
name: "package",
value: "features.nested.simple.feature",
},
]),
}),
]),
);
});

it("sets label from env variables", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"], undefined, undefined, {
ALLURE_LABEL_A: "a",
ALLURE_LABEL_B: "b",
const { tests } = await runCucumberInlineTest(["simple"], ["simple"], {
env: {
ALLURE_LABEL_A: "a",
ALLURE_LABEL_B: "b",
},
});

expect(tests).toHaveLength(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, it } from "vitest";
import { runCucumberInlineTest } from "../../../utils.js";

it("handles runtime descriptions", async () => {
const { tests } = await runCucumberInlineTest(["description"], ["runtime/legacy/description"], false);
const { tests } = await runCucumberInlineTest(["description"], ["runtime/legacy/description"], { parallel: false });

expect(tests).toHaveLength(3);
expect(tests).toContainEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LabelName } from "allure-js-commons";
import { runCucumberInlineTest } from "../../../utils.js";

it("handles runtime labels", async () => {
const { tests } = await runCucumberInlineTest(["labels"], ["runtime/legacy/labels"], false);
const { tests } = await runCucumberInlineTest(["labels"], ["runtime/legacy/labels"], { parallel: false });

expect(tests).toHaveLength(3);
expect(tests).toContainEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LinkType } from "allure-js-commons";
import { runCucumberInlineTest } from "../../../utils.js";

it("handles runtime links", async () => {
const { tests } = await runCucumberInlineTest(["links"], ["runtime/legacy/links"], false);
const { tests } = await runCucumberInlineTest(["links"], ["runtime/legacy/links"], { parallel: false });

expect(tests).toHaveLength(5);
expect(tests).toContainEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LabelName, Stage, Status } from "allure-js-commons";
import { runCucumberInlineTest } from "../../../utils.js";

it("handles runtime steps", async () => {
const { tests } = await runCucumberInlineTest(["steps"], ["runtime/legacy/steps"], false);
const { tests } = await runCucumberInlineTest(["steps"], ["runtime/legacy/steps"], { parallel: false });
expect(tests).toHaveLength(2);

const test1 = tests.find((test) => test.name === "succeed");
Expand Down
Loading

0 comments on commit 5ee7a1e

Please sign in to comment.