Skip to content

200 testing formatter idempotence #294

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

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
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
57 changes: 36 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,41 @@
name: Node.js CI

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
push:
branches: ["develop"]
pull_request:
branches: ["develop"]

jobs:
build:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm install
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'
build:
strategy:
matrix:
os: [windows-latest]
runs-on: ${{ matrix.os }}

defaults:
run:
working-directory: ${{ github.workspace }}\resources\stabilityTests

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm install
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'

- run: xvfb-run -a npm run get-ade-test
if: runner.os == 'Linux'
- run: npm run get-ade-test
if: runner.os != 'Linux'

- run: xvfb-run -a npm run stability-test
if: runner.os == 'Linux'
- run: npm run stability-test
if: runner.os != 'Linux'
Comment on lines +14 to +44

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules
*.vsix
resources/ade
resources/testResults
resources/testResultsIdempotence
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}, {
},
{
"name": "Stability Tests",
"type": "extensionHost",
"request": "launch",
Expand All @@ -58,10 +59,9 @@
"preLaunchTask": "${defaultBuildTask}"
}
],

"folders": [
{
"path": "${workspaceFolder}/resources/samples"
}
]
}
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
"[typescript]" : {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

"editor.formatOnSave": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@
"copy-test-cases": "copyfiles -u 2 ./resources/samples/* .test_dir/samples",
"copy-test-settings": "copyfiles -u 2 ./resources/samples/.vscode/* .test_dir/samples/",
"test": "node ./out/test/runTest.js",
"get-ade-test": "git clone https://github.com/progress/ADE.git resources/ade"
"get-ade-test": "git clone https://github.com/progress/ADE.git resources/ade",
"stability-test": "node ./out/stability-test/runTest.js"
},
"devDependencies": {
"@electron/rebuild": "^3.3.1",
Expand Down
90 changes: 84 additions & 6 deletions src/stability-test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ let parserHelper: AblParserHelper;

const extensionDevelopmentPath = path.resolve(__dirname, "../../../");
const testResultsDir = join(extensionDevelopmentPath, "resources/testResults");
const testResultsDirIdempotence = join(
extensionDevelopmentPath,
"resources/testResultsIdempotence"
);

const stabilityTestDir = join(extensionDevelopmentPath, "resources/ade");
const extensionsToFind = [".p", ".w", ".cls", ".i"];
Expand All @@ -33,6 +37,7 @@ const testRunTimestamp = new Date()
.replace(/[:.T-]/g, "_")
.substring(0, 19);
const testRunDir = join(testResultsDir, testRunTimestamp);
const testRunDirIdempotence = join(testResultsDirIdempotence, testRunTimestamp);

suite("Extension Test Suite", () => {
console.log("Parser initialized", stabilityTestCases);
Expand All @@ -47,6 +52,7 @@ suite("Extension Test Suite", () => {
});

fs.mkdirSync(testRunDir, { recursive: true });
fs.mkdirSync(testRunDirIdempotence, { recursive: true });

parserHelper = new AblParserHelper(
extensionDevelopmentPath,
Expand All @@ -61,11 +67,14 @@ suite("Extension Test Suite", () => {
);
});

let fileId = 0;

stabilityTestCases.forEach((cases) => {
test(`Symbol test: ${cases}`, () => {
stabilityTest(cases);
// test(`Empty space test: ${cases}`, () => {
// stabilityTest(cases);
// }).timeout(10000);

// try to run 3 times
test(`Idempotence test: ${cases}`, () => {
runFormattingNTimes(cases, 2);
}).timeout(10000);
});
});
Expand All @@ -75,8 +84,10 @@ function stabilityTest(name: string): void {
enableFormatterDecorators();

const beforeText = getInput(name);
const beforeCount = countActualSymbols(beforeText);
const afterText = format(beforeText, name);

const beforeCount = countActualSymbols(beforeText);

const afterCount = countActualSymbols(afterText);

if (beforeCount !== afterCount) {
Expand All @@ -98,7 +109,74 @@ function stabilityTest(name: string): void {
After: ${afterFilePath}
`);
}
// assert.strictEqual(beforeCount, afterCount);
}

function idempotenceTest(name: string) {
ConfigurationManager2.getInstance();
enableFormatterDecorators();

const beforeText = getInput(name);

const afterText = format(beforeText, name);

ConfigurationManager2.getInstance();
enableFormatterDecorators();

const afterText2 = format(afterText, name);

if (afterText !== afterText2) {
const fileName = path.basename(name, path.extname(name));
const afterFilePath = join(
testRunDirIdempotence,
`${fileName}_before${path.extname(name)}`
);
const after2FilePath = join(
testRunDirIdempotence,
`${fileName}_after${path.extname(name)}`
);

fs.writeFileSync(afterFilePath, afterText);
fs.writeFileSync(after2FilePath, afterText2);

assert.fail(`Text mismach
After: ${afterFilePath}
After2: ${after2FilePath}
`);
}
}

function runFormattingNTimes(name: string, n: number) {
let currentText = getInput(name);
const symbolCount = countActualSymbols(currentText);
for (let i = 1; i < n; i++) {
if (symbolCount < 500 || symbolCount > 1500) {
console.log("Skipping test", name);
return;
}
const afterText = format(currentText, name);
fs.writeFileSync(name, afterText);
if (i == n - 1 && currentText !== afterText) {
const fileName = path.basename(name, path.extname(name));
const afterFilePath = join(
testRunDirIdempotence,
`${fileName}_before${path.extname(name)}`
);
const after2FilePath = join(
testRunDirIdempotence,
`${fileName}_after${path.extname(name)}`
);

fs.writeFileSync(afterFilePath, currentText);
fs.writeFileSync(after2FilePath, afterText);

assert.fail(`Text mismach
After: ${afterFilePath}
After2: ${after2FilePath}
`);
}

currentText = afterText;
}
}

function getInput(fileName: string): string {
Expand Down