Skip to content

Commit

Permalink
resolved problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Duda committed May 28, 2024
1 parent a684df9 commit 33b604b
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 1,475 deletions.
1,658 changes: 197 additions & 1,461 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"html-creator": "^0.7.2",
"nodegit": "^0.28.0-alpha.26",
"ts-morph": "^22.0.0",
"@stoplight/better-ajv-errors": "^1.0.3",
"node-fetch": "^2.7.0",
"ajv": "^4.11.8",
"better-ajv-errors": "^0.6.7"
Expand Down
12 changes: 6 additions & 6 deletions src/Report/ADFValidator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const nodeFetch = require("node-fetch");
const betterAjvErrors = require('better-ajv-errors');
import Ajv from 'ajv';
import { Logger } from '../Logger/Logger';
const betterAjvErrors = require("better-ajv-errors");
import Ajv from "ajv";
import { Logger } from "../Logger/Logger";

export class ADFValidator {
private static SCHEMA_URL = "https://unpkg.com/@atlaskit/[email protected]/dist/json-schema/v1/full.json";

private _schema: Object;
private _schema: unknown;

public constructor() { }

public async loadSchema(): Promise<any> {
public async loadSchema(): Promise<void> {
console.log("[ADFValidator] Fetching latest JSON schema");

const response = await nodeFetch(ADFValidator.SCHEMA_URL);
Expand All @@ -29,7 +29,7 @@ export class ADFValidator {
console.log("[ADFValidator] Validating ADF...");

if (!this._schema) {
throw new Error(`[ADFValidator] Schema is not loaded yet, call await loadSchema() before validation`);
throw new Error("[ADFValidator] Schema is not loaded yet, call await loadSchema() before validation");
}

const ajv = new Ajv({ jsonPointers: true });
Expand Down
4 changes: 2 additions & 2 deletions src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env nodeimport { runUntagCommand } from "./Commands/runUntagCommand";
#!/usr/bin/env node
import { runCommitCommand } from "./Commands/runCommitCommand";
import { runAddCommand } from "./Commands/runAddCommand";
import { runVerifyCommand } from "./Commands/runVerifyCommand";
Expand Down Expand Up @@ -91,5 +91,5 @@ switch (args[0]) {
}

export function getScriptVersion(): string {
return require('../package.json').version;
return require("../package.json").version;
}
5 changes: 2 additions & 3 deletions test/report/reportGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ const initReportGenerator = (root: string) => {
tags.load();

return new ReportGenerator(repository, tags, database, config, [tsReferenceFinder], PRINT_DEBUG_INFO);
}
};


describe("Report generation works as expected", async () => {
describe("Report generation works as expected", () => {
it("After making a change in a tagged file, the change is correctly described by generated report", async () => {
const FOLDER_PATH = makeUniqueFolderForTest();
const REPO_PATH = cloneMockRepositoryToFolder(FOLDER_PATH);
Expand Down
10 changes: 10 additions & 0 deletions test/scope/qualityTests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getFirstLine } from "../utils/utils";

describe("Quality checks", () => {
it("Check if the first line of scope.ts is correct (sometimes there is 'nodeimport' there)", async () => {
const EXPECTED_FIRST_LINE = "#!/usr/bin/env node";

const firstLine = await getFirstLine("./src/scope.ts");
expect(firstLine).toBe(EXPECTED_FIRST_LINE);
});
});
20 changes: 18 additions & 2 deletions test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { MOCK_REMOTE_URL, MOCK_REPOSITORY, TEST_DATA_FOLDER } from "./globals";

import * as uuid from "uuid";
import { GitRepository } from "../../src/Git/GitRepository";
import rimraf from "rimraf";
import { execSync } from "child_process";
import * as rimraf from "rimraf";
import fs from "fs";
import readline from "readline";

// Mocked repository

Expand Down Expand Up @@ -162,4 +164,18 @@ export const commitFilesUsingGitNatively = (
commitMessage = "test commit"
) => {
execSync(`cd ${repositoryPath} && git add ${fileNames.join(" ")} && git commit -m "${commitMessage}"`);
};
};

// https://stackoverflow.com/questions/28747719/what-is-the-most-efficient-way-to-read-only-the-first-line-of-a-file-in-node-js
export async function getFirstLine(pathToFile: string): Promise<string> {
const readable = fs.createReadStream(pathToFile);
const reader = readline.createInterface({ input: readable });
const line: string = await new Promise((resolve) => {
reader.on("line", (line) => {
reader.close();
resolve(line);
});
});
readable.close();
return line;
}

0 comments on commit 33b604b

Please sign in to comment.