Skip to content

Commit

Permalink
Rebuild specs to remove info dependent on git repo
Browse files Browse the repository at this point in the history
As mentioned in #1977
  • Loading branch information
Gerrit0 committed Jul 2, 2022
1 parent ecb6e00 commit 7993ce7
Show file tree
Hide file tree
Showing 23 changed files with 810 additions and 766 deletions.
38 changes: 27 additions & 11 deletions scripts/rebuild_specs.js
Expand Up @@ -6,6 +6,8 @@ const fs = require("fs");
const path = require("path");
const TypeDoc = require("..");
const { getExpandedEntryPointsForPaths } = require("../dist/lib/utils");
const { ok } = require("assert");
const { SourceReference } = require("..");

const base = path.join(__dirname, "../src/test/converter");

Expand All @@ -21,6 +23,23 @@ app.bootstrap({
logLevel: TypeDoc.LogLevel.Warn,
gitRevision: "fake",
});
app.serializer.addSerializer({
priority: -1,
supports(obj) {
return obj instanceof SourceReference;
},
/**
* @param {SourceReference} ref
*/
toObject(ref, obj, _serializer) {
if (obj.url) {
obj.url = `typedoc://${obj.url.substring(
obj.url.indexOf(ref.fileName)
)}`;
}
return obj;
},
});

/** @type {[string, () => void, () => void][]} */
const conversions = [
Expand Down Expand Up @@ -68,20 +87,17 @@ function rebuildConverterTests(dirs) {
if (fs.existsSync(out)) {
TypeDoc.resetReflectionID();
before();
const result = app.converter.convert(
getExpandedEntryPointsForPaths(
app.logger,
[fullPath],
app.options,
[program]
)
const entry = getExpandedEntryPointsForPaths(
app.logger,
[fullPath],
app.options,
[program]
);
ok(entry, "Missing entry point");
const result = app.converter.convert(entry);
const serialized = app.serializer.toObject(result);

const data =
JSON.stringify(serialized, null, " ")
.split(TypeDoc.normalizePath(base))
.join("%BASE%") + "\n";
const data = JSON.stringify(serialized, null, " ") + "\n";
after();
fs.writeFileSync(out, data);
}
Expand Down
7 changes: 6 additions & 1 deletion src/lib/serialization/components.ts
Expand Up @@ -17,7 +17,12 @@ export interface SerializerComponent<T> {
*/
readonly priority: number;

supports(item: unknown): item is T;
/**
* Technically this should return `item is T`, but that doesn't play nicely
* with inference, so allow the looser `boolean` return type.
* @param item
*/
supports(item: unknown): boolean;

toObject(
item: T,
Expand Down
12 changes: 5 additions & 7 deletions src/test/converter.test.ts
@@ -1,7 +1,7 @@
import { deepStrictEqual as equal, ok } from "assert";
import * as FS from "fs";
import * as Path from "path";
import { normalizePath, ProjectReflection, resetReflectionID } from "..";
import { ProjectReflection, resetReflectionID } from "..";
import { getExpandedEntryPointsForPaths } from "../lib/utils";
import {
getConverterApp,
Expand Down Expand Up @@ -76,14 +76,12 @@ describe("Converter", function () {
const specs = JSON.parse(
FS.readFileSync(specsFile, "utf-8")
);
let data = JSON.stringify(
result && app.serializer.toObject(result),
null,
" "
// Pass data through a parse/stringify to get rid of undefined properties
const data = JSON.parse(
JSON.stringify(app.serializer.toObject(result))
);
data = data.split(normalizePath(base)).join("%BASE%");

equal(JSON.parse(data), specs);
equal(data, specs);
});
}
});
Expand Down
12 changes: 6 additions & 6 deletions src/test/converter/alias/specs.json
Expand Up @@ -24,7 +24,7 @@
"fileName": "alias.ts",
"line": 14,
"character": 12,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L14"
"url": "typedoc://alias.ts#L14"
}
],
"typeParameters": [
Expand Down Expand Up @@ -76,7 +76,7 @@
"fileName": "alias.ts",
"line": 19,
"character": 12,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L19"
"url": "typedoc://alias.ts#L19"
}
],
"typeParameters": [
Expand Down Expand Up @@ -129,7 +129,7 @@
"fileName": "alias.ts",
"line": 4,
"character": 12,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L4"
"url": "typedoc://alias.ts#L4"
}
],
"typeParameters": [
Expand All @@ -154,7 +154,7 @@
"fileName": "alias.ts",
"line": 4,
"character": 34,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L4"
"url": "typedoc://alias.ts#L4"
}
],
"signatures": [
Expand Down Expand Up @@ -226,7 +226,7 @@
"fileName": "alias.ts",
"line": 9,
"character": 12,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L9"
"url": "typedoc://alias.ts#L9"
}
],
"type": {
Expand Down Expand Up @@ -260,7 +260,7 @@
"fileName": "alias.ts",
"line": 4,
"character": 0,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L4"
"url": "typedoc://alias.ts#L4"
}
]
}

0 comments on commit 7993ce7

Please sign in to comment.