Skip to content

Commit

Permalink
Convert test suite to ESM (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored Jun 13, 2024
1 parent c7d6d39 commit b7cd800
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
globals: {
...globals.mocha,
...globals.node,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"scripts": {
"lint": "eslint ./",
"test": "npm run lint && npm run unit-test",
"unit-test": "nyc mocha tests/**/*.js"
"unit-test": "nyc mocha tests/**/*.mjs"
},
"peerDependencies": {
"eslint": ">=2.0.0 <= 9.x"
Expand Down
13 changes: 9 additions & 4 deletions tests/index.js → tests/index.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* eslint-env mocha */
'use strict';

const plugin = require('..');
import plugin from '../index.js';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));

let rules = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
.map((f) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';

const rule = require('../../../lib/rules/missing-assertion');
import {ecmaVersion} from './utils.mjs';
import rule from '../../../lib/rules/missing-assertion.js';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {RuleTester} = require('eslint');
const {ecmaVersion} = require('./utils');

let ruleTester = new RuleTester();
ruleTester.run('missing-assertion', rule, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const rule = require('../../../lib/rules/no-inner-compare');
import rule from '../../../lib/rules/no-inner-compare.js';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {RuleTester} = require('eslint');

let ruleTester = new RuleTester();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';

const rule = require('../../../lib/rules/no-inner-literal');
import rule from '../../../lib/rules/no-inner-literal.js';
import {ecmaVersion} from './utils.mjs';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {RuleTester} = require('eslint');
const {ecmaVersion} = require('./utils');

let ruleTester = new RuleTester();
ruleTester.run('no-inner-literal', rule, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const rule = require('../../../lib/rules/terminating-properties');
import rule from '../../../lib/rules/terminating-properties.js';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {RuleTester} = require('eslint');

let ruleTester = new RuleTester();
Expand Down
9 changes: 4 additions & 5 deletions tests/lib/rules/utils.js → tests/lib/rules/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const eslintPkg = require('eslint/package.json');

const USE_LANGUAGE_OPTIONS = eslintPkg.version.startsWith('9.');

function ecmaVersion(version) {
export function ecmaVersion(version) {
if (USE_LANGUAGE_OPTIONS) {
return {
languageOptions: {
Expand All @@ -17,7 +20,3 @@ function ecmaVersion(version) {
}
}
}

module.exports = {
ecmaVersion
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

const importFrom = require('import-from');
const {expect} = require('chai');
import { createRequire } from 'node:module';
import importFrom from 'import-from';
import {expect} from 'chai';
import findExpectCall from '../../../lib/util/find-expect-call.js';

const require = createRequire(import.meta.url);
const espree = importFrom(require.resolve('eslint'), 'espree');
const findExpectCall = require('../../../lib/util/find-expect-call');

describe('find-expect-call util', function () {
it('Finds expect statements which are considered member expressions', function () {
Expand Down

0 comments on commit b7cd800

Please sign in to comment.