Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions templates/_github/workflows/test-and-release.yml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ const templateFunction: TemplateFunction = answers => {
const useReleaseScript = answers.releaseScript === "yes";
const isGitHub = answers.target === "github";

const ltsNodeVersion = "20.x";
const adapterTestVersions = ["20.x", "22.x", "24.x"];
// Determine the LTS version and test versions based on the minimum Node.js version selected
const minNodeVersion = answers.nodeVersion || "20";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a constant for the "recommended nodejs fall back version" in a new file for such fallbacks (are there more such fallbacks in the code?) and import from there

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please add a constant for the "recommended nodejs fall back version" in a new file for such fallbacks (are there more such fallbacks in the code?) and import from there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new constants file src/lib/constants.ts with RECOMMENDED_NODE_VERSION_FALLBACK constant. Found and updated three locations where "20" was used as a Node.js version fallback:

  • templates/_github/workflows/test-and-release.yml.ts
  • templates/package.json.ts
  • templates/tsconfig.json.ts

All now import and use the centralized constant. Commit fb9ad97.

const ltsNodeVersion = `${minNodeVersion}.x`;

// Filter test versions to only include versions >= the minimum version
const allTestVersions = ["20.x", "22.x", "24.x"];
const minVersionNumber = parseInt(minNodeVersion, 10);
const adapterTestVersions = allTestVersions.filter(version => {
const versionNumber = parseInt(version.split('.')[0], 10);
return versionNumber >= minVersionNumber;
});

const adapterTestOS = ["ubuntu-latest", "windows-latest", "macos-latest"];

Expand Down
63 changes: 63 additions & 0 deletions test/create-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,5 +654,68 @@ describe("adapter creation =>", () => {
);
});
});

describe("GitHub Actions workflow Node.js version filtering", () => {
it("should only test supported Node.js versions", async () => {
const testCases = [
{
nodeVersion: "20",
expectedVersions: ["20.x", "22.x", "24.x"],
expectedLts: "20.x",
},
{
nodeVersion: "22",
expectedVersions: ["22.x", "24.x"],
expectedLts: "22.x",
},
{
nodeVersion: "24",
expectedVersions: ["24.x"],
expectedLts: "24.x",
},
];

for (const testCase of testCases) {
const answers: Answers = {
...baseAnswers,
nodeVersion: testCase.nodeVersion as "20" | "22" | "24",
target: "github",
releaseScript: "yes",
};

const files = await createAdapter(answers);
const workflowFile = files.find(f => f.name.endsWith("test-and-release.yml"));

if (!workflowFile) {
throw new Error(`Workflow file not found for Node.js ${testCase.nodeVersion}`);
}

const content = workflowFile.content;

// Check that the matrix includes only the expected versions
const matrixMatch = content.match(/node-version: \[(.*?)\]/);
if (!matrixMatch) {
throw new Error(`Matrix node versions not found for Node.js ${testCase.nodeVersion}`);
}

const actualVersions = matrixMatch[1].split(", ").map(v => v.trim());
actualVersions.should.deep.equal(testCase.expectedVersions,
`For Node.js ${testCase.nodeVersion}, expected versions ${testCase.expectedVersions.join(", ")} but got ${actualVersions.join(", ")}`);

// Check that the LTS version is correct
const ltsMatches = content.match(/node-version: '(\d+\.x)'/g) || [];
if (ltsMatches.length === 0) {
throw new Error(`LTS node version not found for Node.js ${testCase.nodeVersion}`);
}

// All LTS references should use the expected version
for (const ltsMatch of ltsMatches) {
const ltsVersion = ltsMatch.match(/'(\d+\.x)'/)?.[1];
ltsVersion.should.equal(testCase.expectedLts,
`For Node.js ${testCase.nodeVersion}, expected LTS ${testCase.expectedLts} but got ${ltsVersion}`);
}
}
});
});
});
});