Skip to content
Draft
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
6 changes: 6 additions & 0 deletions test/fixtures/linter/projects/globals/webapp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sap.app": {
"id": "com.example.app",
"type": "application"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function globalFactory() {}
sap.ui.getCore().attachInit(function () {
sap.ui.require([], globalFactory);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function globalFactory() {

}
sap.ui.getCore().attachInit(function () {});
30 changes: 30 additions & 0 deletions test/lib/autofix/autofix.projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,33 @@ test.serial("lint: All files of library with sap.ui.core namespace", async (t) =
t.true(writeFilePath.startsWith(projectPath), `${writeFilePath} should start with ${projectPath}`);
}
});

test.serial("lint: All files of globals application", async (t) => {
const projectPath = path.join(fixturesProjectsPath, "globals");
const {linterEngine} = t.context;

const res = await linterEngine.lint({
rootDir: projectPath,
fix: true,
});

t.snapshot(preprocessLintResultsForSnapshot(res));
t.truthy(t.context.autofixSpy.callCount >= 1);
let expectedWrites = 0;
for (let i = t.context.autofixSpy.callCount - 1; i >= 0; i--) {
const autofixResult = await t.context.autofixSpy.getCall(i).returnValue;
expectedWrites += autofixResult.size;
const autofixResultEntries = Array.from(autofixResult.entries());
autofixResultEntries.sort((a, b) => a[0].localeCompare(b[0]));
for (const [filePath, content] of autofixResultEntries) {
t.snapshot(content, `AutofixResult iteration #${i}: ${filePath}`);
}
}

// Ensure that all files are written using an absolute path within the project
t.is(t.context.writeFileStub.callCount, expectedWrites);
const writeFilePaths = t.context.writeFileStub.args.map((args) => args[0]);
for (const writeFilePath of writeFilePaths) {
t.true(writeFilePath.startsWith(projectPath), `${writeFilePath} should start with ${projectPath}`);
}
});
119 changes: 119 additions & 0 deletions test/lib/autofix/snapshots/autofix.projects.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,122 @@ Generated by [AVA](https://avajs.dev).
warningCount: 0,
},
]

## lint: All files of globals application

> Snapshot 1

[
{
coverageInfo: [],
errorCount: 3,
fatalErrorCount: 0,
filePath: 'webapp/test/globalFactory1.js',
messages: [
{
column: 1,
line: 2,
message: 'Access of global variable \'sap\' (sap.ui.getCore)',
ruleId: 'no-globals',
severity: 2,
ui5TypeInfo: undefined,
},
{
column: 8,
line: 2,
message: 'Call to deprecated function \'getCore\' (sap.ui.getCore)',
ruleId: 'no-deprecated-api',
severity: 2,
ui5TypeInfo: {
kind: 'Function',
name: 'getCore',
parent: {
kind: 'Namespace',
name: 'ui',
parent: {
kind: 'Namespace',
name: 'sap',
},
},
},
},
{
column: 18,
line: 2,
message: 'Call to deprecated function \'attachInit\' of class \'Core\'',
ruleId: 'no-deprecated-api',
severity: 2,
ui5TypeInfo: {
kind: 'Method',
name: 'attachInit',
parent: {
kind: 'Class',
name: 'Core',
parent: {
kind: 'Module',
library: 'sap.ui.core',
name: 'sap/ui/core/Core',
},
},
},
},
],
warningCount: 0,
},
{
coverageInfo: [],
errorCount: 3,
fatalErrorCount: 0,
filePath: 'webapp/test/globalFactory2.js',
messages: [
{
column: 1,
line: 4,
message: 'Access of global variable \'sap\' (sap.ui.getCore)',
ruleId: 'no-globals',
severity: 2,
ui5TypeInfo: undefined,
},
{
column: 8,
line: 4,
message: 'Call to deprecated function \'getCore\' (sap.ui.getCore)',
ruleId: 'no-deprecated-api',
severity: 2,
ui5TypeInfo: {
kind: 'Function',
name: 'getCore',
parent: {
kind: 'Namespace',
name: 'ui',
parent: {
kind: 'Namespace',
name: 'sap',
},
},
},
},
{
column: 18,
line: 4,
message: 'Call to deprecated function \'attachInit\' of class \'Core\'',
ruleId: 'no-deprecated-api',
severity: 2,
ui5TypeInfo: {
kind: 'Method',
name: 'attachInit',
parent: {
kind: 'Class',
name: 'Core',
parent: {
kind: 'Module',
library: 'sap.ui.core',
name: 'sap/ui/core/Core',
},
},
},
},
],
warningCount: 0,
},
]
Binary file modified test/lib/autofix/snapshots/autofix.projects.ts.snap
Binary file not shown.
Loading