Skip to content

Commit

Permalink
fix: use jest to do version test
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jul 20, 2021
1 parent 5cbc92b commit 616bd3a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test:server-protocols": "yarn build:server-protocols && lerna run test --scope '@aws-sdk/*-server'",
"pretest:e2e": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/{client-cloudformation,karma-credential-loader}' --include-dependencies build",
"test:e2e": "node ./tests/e2e/index.js",
"test:versions": "node tests/versions/tslib.js",
"test:versions": "jest --config tests/versions/jest.config.js tests/versions/index.spec.ts",
"local-publish": "node ./scripts/verdaccio-publish/index.js"
},
"repository": {
Expand Down
33 changes: 33 additions & 0 deletions tests/versions/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Validate the tslib and tsc version is consistent and corresponds to each other.
*/
import { execSync } from "child_process";
import { readFileSync } from "fs";
import JSON from "json5";
import { join } from "path";

type PackageInfo = {
name: string;
version: string;
private: boolean;
location: string;
};

test("tslib and tsc version should be consistent within workspace.", () => {
const expectedVersions: { [name: string]: string } = JSON.parse(
readFileSync(join(__dirname, "versions.jsonc"), "utf8")
);
const packagesInfo: PackageInfo[] = JSON.parse(execSync("./node_modules/.bin/lerna list -l --json").toString());
for (const { name, location } of packagesInfo) {
const manifest = readFileSync(`${location}/package.json`, "utf8");
const { dependencies, devDependencies } = JSON.parse(manifest);
for (const [expectedName, expectedVersion] of Object.entries(expectedVersions)) {
if (expectedName === name) {
const actualVersion = dependencies[expectedName] || devDependencies[expectedName];
if (actualVersion !== expectedVersion) {
fail(`Expected version ${expectedVersion} for ${name} in ${location}, but got ${actualVersion}`);
}
}
}
}
});
4 changes: 4 additions & 0 deletions tests/versions/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: "ts-jest",
testMatch: ["**/*.spec.ts"],
};
24 changes: 0 additions & 24 deletions tests/versions/tslib.js

This file was deleted.

File renamed without changes.

0 comments on commit 616bd3a

Please sign in to comment.