Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier and resolvejson #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.describe("validateSourceMap", () => {
"--originalFolder",
`test-projects/${project}/original/`,
]);
assert.deepEqual(foo, { isValid: true });
assert.deepEqual(foo, { isValid: true, errors: [] });
});
});
test(`should return a valid result when given a valid source map for wasm project with name "project4"`, async () => {
Expand All @@ -28,6 +28,6 @@ test.describe("validateSourceMap", () => {
"--originalFolder",
`test-projects/project4/original/`,
]);
assert.deepEqual(foo, { isValid: true });
assert.deepEqual(foo, { isValid: true, errors: [] });
});
});
28 changes: 18 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ValidationFail } from "./util/ValidationResult.js";
import { ValidationContext } from "./util/ValidationContext.js";

type ValidatorResult =
| { isValid: true }
| { isValid: false, errors: Error[] };
| { isValid: true; errors: [] }
| { isValid: false; errors: Error[] };

export default async function main(args: string[]): Promise<ValidatorResult> {
const parser = yargs(args)
Expand Down Expand Up @@ -41,12 +41,16 @@ export default async function main(args: string[]): Promise<ValidatorResult> {
const originalFolderPath = path.resolve(argv.o);
const generatedFilePath = path.resolve(argv.g);

const context = ValidationContext.from(sourceMapPath, originalFolderPath, generatedFilePath)
const result = await validations.validate(context)
const context = ValidationContext.from(
sourceMapPath,
originalFolderPath,
generatedFilePath
);
const result = await validations.validate(context);

return result instanceof ValidationFail
? { isValid: false, errors: result.errors }
: { isValid: true };
? { isValid: false, errors: result.errors }
: { isValid: true, errors: [] };
}

// Check if the script is called from the command line
Expand All @@ -60,10 +64,14 @@ const executedFileNormalized = executedFile.replace(/\\/g, "/");
if (currentFileNormalized === executedFileNormalized) {
const result = await main(process.argv.slice(2));
if (result.isValid) {
console.log("Source map is valid.")
process.exit(0)
console.log("Source map is valid.");
process.exit(0);
} else {
console.error(`Source map is invalid:\n${result.errors.map(x => x.message).join("\n\n")}`)
process.exit(1)
console.error(
`Source map is invalid:\n${result.errors
.map((x) => x.message)
.join("\n\n")}`
);
process.exit(1);
}
}
23 changes: 18 additions & 5 deletions src/spec-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import assert from "node:assert";
import path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from 'node:url';
import { fileURLToPath } from "node:url";

import validateSourceMap from "./index.js";
import sourceMapSpecTests from "../source-map-tests/source-map-spec-tests.json" assert { type: "json" };

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const specResourcesBaseDir = path.resolve(__dirname, "../../source-map-tests/resources");
const specResourcesBaseDir = path.resolve(
__dirname,
"../../source-map-tests/resources"
);

// These tests are known failures that aren't easily fixed at the moment.
const skippedTests = [
Expand All @@ -23,7 +26,9 @@ const skippedTests = [

test.describe("runSourceMapSpecTests", () => {
sourceMapSpecTests.tests.forEach((testCase) => {
test(`The source map spec test case "${testCase.name}" has ${testCase.sourceMapIsValid ? "a valid" : "an invalid"} source map`, async (t) => {
test(`The source map spec test case "${testCase.name}" has ${
testCase.sourceMapIsValid ? "a valid" : "an invalid"
} source map`, async (t) => {
if (skippedTests.includes(testCase.name)) {
t.skip();
return;
Expand All @@ -37,9 +42,17 @@ test.describe("runSourceMapSpecTests", () => {
`${specResourcesBaseDir}`,
]);
if (testCase.sourceMapIsValid)
assert.deepEqual(result, { isValid: true }, "expected source map to be valid");
assert.deepEqual(
result,
{ isValid: true, errors: [] },
"expected source map to be valid"
);
else
assert.equal(result.isValid, false, "expected source map to be invalid");
assert.equal(
result.isValid,
false,
"expected source map to be invalid"
);
});
});
});
Loading