Skip to content

Commit

Permalink
fix:static class blocks are not enabled babel error (#8267)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose
_Describe the problem you want to address or the feature you want to
implement._

## Approach
_Describe how your changes address the issue or implement the desired
functionality in as much detail as possible._

## References
closes #8245

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail

---------

Co-authored-by: Bayheck <[email protected]>
  • Loading branch information
Bayheck and Bayheck authored Sep 16, 2024
1 parent 7fb159d commit 647ecae
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 173 deletions.
345 changes: 173 additions & 172 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-async-to-generator": "^7.22.5",
"@babel/plugin-transform-class-static-block": "^7.24.7",
"@babel/plugin-transform-exponentiation-operator": "^7.22.5",
"@babel/plugin-transform-for-of": "^7.22.15",
"@babel/plugin-transform-runtime": "7.23.3",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/babel/load-libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ export default function loadLibs ({ esm } = {}) {
presetReact: getPresetReact(),
proposalPrivateMethods: [require('@babel/plugin-proposal-private-methods'), { loose: true }],
proposalClassProperties: [require('@babel/plugin-proposal-class-properties'), { loose: true }],
transformClassStaticBlock: require('@babel/plugin-transform-class-static-block'),
};
}
3 changes: 2 additions & 1 deletion src/compiler/test-file/formats/es-next/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ export default class ESNextTestFileCompiler extends APIBasedTestFileCompilerBase
moduleResolver,
proposalPrivateMethods,
proposalClassProperties,
transformClassStaticBlock,
} = loadBabelLibs({ esm });

const opts = Object.assign({}, BASE_BABEL_OPTIONS, {
presets: [presetStage2, presetEnvForTestCode, presetReact],
plugins: [transformRuntime, moduleResolver, proposalPrivateMethods, proposalClassProperties],
plugins: [transformRuntime, moduleResolver, proposalPrivateMethods, proposalClassProperties, transformClassStaticBlock],
sourceMaps: 'inline',
filename,
});
Expand Down
18 changes: 18 additions & 0 deletions test/server/compiler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ describe('Compiler', function () {
expect(results.inventory).to.equal('42 yoyo');
});
});

it('Should compile test with static class blocks', function () {
const sources = [
'test/server/data/test-suites/class-with-static/testfile.js',
];

return compile(sources)
.then(function (compiled) {
const tests = compiled.tests;
const fixtures = compiled.fixtures;

expect(tests.length).eql(1);
expect(fixtures.length).eql(1);

expect(tests[0].name).eql('Test');
expect(fixtures[0].name).eql('Fixture');
});
});
});

describe('TypeScript', function () {
Expand Down
5 changes: 5 additions & 0 deletions test/server/data/test-suites/class-with-static/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ClassThatUsesStatic {
static { this.foo = true; }
}

export default ClassThatUsesStatic;
7 changes: 7 additions & 0 deletions test/server/data/test-suites/class-with-static/testfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ClassThatUsesStatic from './dep.js';

fixture('Fixture');

test('Test', async () => {
ClassThatUsesStatic.foo;
});

0 comments on commit 647ecae

Please sign in to comment.