Skip to content

Commit

Permalink
chore: Migrating third-party parser tests to MakeJS (#15431)
Browse files Browse the repository at this point in the history
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
  • Loading branch information
liuxingbaoyu and JLHwung committed Feb 18, 2023
1 parent 9be2c7f commit 1004037
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
18 changes: 3 additions & 15 deletions Makefile
Expand Up @@ -149,11 +149,7 @@ test-ci-coverage:
rm -rf coverage/tmp

bootstrap-flow:
rm -rf build/flow
mkdir -p build
git clone --filter=blob:none --sparse --single-branch --shallow-since=2021-05-01 https://github.com/facebook/flow.git build/flow
cd build/flow && git sparse-checkout set "src/parser/test/flow"
cd build/flow && git checkout -q $(FLOW_COMMIT)
$(MAKEJS) bootstrap-flow

test-flow:
$(NODE) scripts/parser-tests/flow
Expand All @@ -162,11 +158,7 @@ test-flow-update-allowlist:
$(NODE) scripts/parser-tests/flow --update-allowlist

bootstrap-typescript:
rm -rf ./build/typescript
mkdir -p ./build
git clone --filter=blob:none --sparse --single-branch --shallow-since=2022-04-01 https://github.com/microsoft/TypeScript.git ./build/typescript
cd build/typescript && git sparse-checkout set "tests"
cd build/typescript && git checkout -q $(TYPESCRIPT_COMMIT)
$(MAKEJS) bootstrap-typescript

test-typescript:
$(NODE) scripts/parser-tests/typescript
Expand All @@ -175,11 +167,7 @@ test-typescript-update-allowlist:
$(NODE) scripts/parser-tests/typescript --update-allowlist

bootstrap-test262:
rm -rf build/test262
mkdir -p build
git clone --filter=blob:none --sparse --single-branch --shallow-since=2021-05-01 https://github.com/tc39/test262.git build/test262
cd build/test262 && git sparse-checkout set "test" "harness"
cd build/test262 && git checkout -q $(TEST262_COMMIT)
$(MAKEJS) bootstrap-test262

test-test262:
$(NODE) scripts/parser-tests/test262
Expand Down
2 changes: 1 addition & 1 deletion Makefile.js

Large diffs are not rendered by default.

50 changes: 49 additions & 1 deletion Makefile.source.mjs
@@ -1,7 +1,7 @@
import "shelljs/make.js";
import path from "path";
import { execFileSync } from "child_process";
import { writeFileSync } from "fs";
import { readFileSync, writeFileSync } from "fs";

/**
* @type {import("shelljs")}
Expand Down Expand Up @@ -389,6 +389,54 @@ target["test-cov"] = function () {
);
};

function bootstrapParserTests(name, repoURL, subPaths) {
function getParserTestsCommit(id) {
const content = readFileSync("./Makefile", "utf8");
const commit = content.match(new RegExp(`${id}_COMMIT = (\\w{40})`))[1];
if (!commit) throw new Error(`Could not find ${id}_COMMIT in Makefile`);
return commit;
}

const dir = "./build/" + name.toLowerCase();

shell.rm("-rf", dir);
shell.mkdir("-p", "build");

exec("git", [
"clone",
"--filter=blob:none",
"--sparse",
"--single-branch",
"--shallow-since='2 years ago'",
repoURL,
dir,
]);

exec("git", ["sparse-checkout", "set", ...subPaths], dir);
exec("git", ["checkout", "-q", getParserTestsCommit(name)], dir);
}

target["bootstrap-test262"] = function () {
bootstrapParserTests("TEST262", "https://github.com/tc39/test262.git", [
"test",
"harness",
]);
};

target["bootstrap-typescript"] = function () {
bootstrapParserTests(
"TYPESCRIPT",
"https://github.com/microsoft/TypeScript.git",
["tests"]
);
};

target["bootstrap-flow"] = function () {
bootstrapParserTests("FLOW", "https://github.com/facebook/flow.git", [
"src/parser/test/flow",
]);
};

/**
* PUBLISH
*/
Expand Down

0 comments on commit 1004037

Please sign in to comment.