Skip to content

Commit

Permalink
fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Apr 18, 2024
1 parent e2fe4d4 commit f14afdd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class SourceFileLinter {
constructor(
context: LinterContext, resourcePath: ResourcePath, sourceFile: ts.SourceFile, sourceMap: string | undefined,
checker: ts.TypeChecker, reportCoverage: boolean | undefined = false,
messageDetails: boolean | undefined = false, manifestContent: string | undefined
messageDetails: boolean | undefined = false, manifestContent?: string | undefined
) {
this.#resourcePath = resourcePath;
this.#sourceFile = sourceFile;
Expand Down Expand Up @@ -498,16 +498,16 @@ export default class SourceFileLinter {

if (manifestJson.manifest?.value === "\"json\"") { // The manifest is an external manifest.json file
const parsedManifestContent =
JSON.parse(this.#manifestContent ?? "") as SAPJSONSchemaForWebApplicationManifestFile;
JSON.parse(this.#manifestContent ?? "{}") as SAPJSONSchemaForWebApplicationManifestFile;

const {rootView, routing} = parsedManifestContent["sap.ui5"] ?? {} as JSONSchemaForSAPUI5Namespace;
// @ts-expect-error async is part of RootViewDefFlexEnabled and RootViewDef
rootViewAsyncFlag = rootView?.async as boolean;
routingAsyncFlag = routing?.config?.async;
} else {
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-explicit-any */
const instanceOfPropsRecord = (obj: any): obj is propsRecord => {
return obj && typeof obj === "object";
return !!obj && typeof obj === "object";
};

let manifestSapui5Section: propsRecord | undefined;
Expand Down
5 changes: 3 additions & 2 deletions test/lib/linter/_linterHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export async function esmockDeprecationText() {
context: LinterContext, filePath: string, sourceFile: SourceFile,
sourceMap: string | undefined, checker: TypeChecker,
reportCoverage: boolean | undefined = false,
messageDetails: boolean | undefined = false
messageDetails: boolean | undefined = false,
manifestContent?: string | undefined
) {
// Don't use sinon's stubs as it's hard to clean after them in this case and it leaks memory.
const linter = new SourceFileLinter(
context, filePath, sourceFile, sourceMap, checker, reportCoverage, messageDetails
context, filePath, sourceFile, sourceMap, checker, reportCoverage, messageDetails, manifestContent
);
linter.getDeprecationText = () => "Deprecated test message";
return linter;
Expand Down
50 changes: 48 additions & 2 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,27 @@ Generated by [AVA](https://avajs.dev).
errorCount: 0,
fatalErrorCount: 0,
filePath: 'webapp/Component.js',
messages: [],
warningCount: 0,
messages: [
{
column: 9,
fatal: undefined,
line: 4,
message: 'Remove the async flag for "sap.ui5/rootView" from the manifest',
messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation',
ruleId: 'ui5-linter-no-sync-loading',
severity: 1,
},
{
column: 9,
fatal: undefined,
line: 4,
message: 'Remove the async flag for "sap.ui5/routing/config" from the manifest',
messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation',
ruleId: 'ui5-linter-no-sync-loading',
severity: 1,
},
],
warningCount: 2,
},
{
coverageInfo: [
Expand Down Expand Up @@ -745,6 +764,33 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
[
{
coverageInfo: [],
errorCount: 0,
fatalErrorCount: 0,
filePath: 'webapp/Component.js',
messages: [
{
column: 9,
fatal: undefined,
line: 4,
message: 'Remove the async flag for "sap.ui5/rootView" from the manifest',
messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation',
ruleId: 'ui5-linter-no-sync-loading',
severity: 1,
},
{
column: 9,
fatal: undefined,
line: 4,
message: 'Remove the async flag for "sap.ui5/routing/config" from the manifest',
messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation',
ruleId: 'ui5-linter-no-sync-loading',
severity: 1,
},
],
warningCount: 2,
},
{
coverageInfo: [],
errorCount: 1,
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.

0 comments on commit f14afdd

Please sign in to comment.