Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage authored and lukpsaxo committed Oct 31, 2023
1 parent 151cfd2 commit 421592b
Showing 1 changed file with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,93 +1,90 @@
const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 71';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module', // top level await can only be used in an ES module
},
});

const chrome71Options = { overrideBrowserslist: 'Chrome >= 71' };
const chrome90Options = { overrideBrowserslist: 'Chrome >= 90' };

ruleTester.run('compat', require('../rule'), {
valid: [
{
code: '[].at(1);',
options: [{ polyfills: ['{Array,String,TypedArray}.prototype.at'] }],
options: [
{ ...chrome71Options, polyfills: ['{Array,String,TypedArray}.prototype.at'] },
],
},
{
code: '"Foo".at(1);',
options: [{ polyfills: ['{Array,String,TypedArray}.prototype.at'] }],
options: [
{ ...chrome71Options, polyfills: ['{Array,String,TypedArray}.prototype.at'] },
],
},
{
code: "new Error('message', { cause: originalError })",
options: [{ polyfills: ['Error.cause'] }],
options: [{ ...chrome71Options, polyfills: ['Error.cause'] }],
},
{
code: "Object.hasOwn(obj, 'prop');",
options: [{ polyfills: ['Object.hasOwn'] }],
options: [{ ...chrome71Options, polyfills: ['Object.hasOwn'] }],
},
],
invalid: [
{
// Obvious array, doesn't need aggressive mode
code: '[].at(1);',
options: [chrome71Options],
errors: [{ message: "ES2022 'Array.prototype.at' method is forbidden." }],
},
{
// Obvious string, doesn't need aggressive mode
code: '"Foo".at(1);',
options: [chrome71Options],
errors: [{ message: "ES2022 'String.prototype.at' method is forbidden." }],
},
{
// Not obvious, needs aggressive mode
code: 'foo.at(1);',
options: [chrome71Options],
errors: [{ message: "ES2022 'Array.prototype.at' method is forbidden." }],
},
{
code: 'class A { a = 0 }',
options: [chrome71Options],
errors: [{ message: "ES2020 field 'a' is forbidden." }],
},
{
code: 'class A { static { } }',
options: [chrome71Options],
errors: [{ message: 'ES2022 class static block is forbidden.' }],
},
{
code: "new Error('message', { cause: originalError })",
options: [chrome71Options],
errors: [{ message: 'ES2022 Error Cause is forbidden.' }],
},
{
code: "Object.hasOwn(obj, 'prop');",
options: [chrome71Options],
errors: [{ message: "ES2022 'Object.hasOwn' method is forbidden." }],
},
{
code: '/./d;',
options: [chrome71Options],
errors: [{ message: "ES2022 RegExp 'd' flag is forbidden." }],
},
{
code: 'await true;',
options: [chrome71Options],
errors: [{ message: "ES2022 top-level 'await' is forbidden." }],
},
],
});

// Browser that supports private fields but not `in` on them - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 90';
jest.resetModules();

const ruleTester2 = new RuleTester({
parserOptions: {
ecmaVersion: 2022,
},
});

ruleTester2.run('compat', require('../rule'), {
valid: [],
invalid: [
{
code: 'class A { #field; foo() { #field in this; } }',
options: [chrome90Options],
errors: [{ message: 'ES2022 private in (`#field in object`) is forbidden.' }],
},
],
Expand Down

0 comments on commit 421592b

Please sign in to comment.