Skip to content

Commit

Permalink
Switch create-rule and integration test to module (#1205)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Apr 23, 2021
1 parent 5a4dc90 commit f1f30c3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
},
"scripts": {
"test": "xo && nyc ava",
"create-rule": "node ./scripts/create-rule.js && npm run generate-rules-table",
"create-rule": "node ./scripts/create-rule.mjs && npm run generate-rules-table",
"run-rules-on-codebase": "node ./test/run-rules-on-codebase/lint.mjs",
"integration": "node ./test/integration/test.js",
"integration": "node ./test/integration/test.mjs",
"smoke": "eslint-remote-tester --config ./test/smoke/eslint-remote-tester.config.js",
"generate-rules-table": "node ./scripts/generate-rules-table.mjs"
},
Expand Down
18 changes: 9 additions & 9 deletions scripts/create-rule.js → scripts/create-rule.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
'use strict';
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import enquirer from 'enquirer';
import {template} from 'lodash-es';
import execa from 'execa';

const fs = require('fs');
const path = require('path');
const enquirer = require('enquirer');
const {template} = require('lodash');
const execa = require('execa');

const ROOT = path.join(__dirname, '..');
const dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.join(dirname, '..');

function checkFiles(ruleId) {
const files = [
Expand All @@ -24,7 +24,7 @@ function checkFiles(ruleId) {
}

function renderTemplate({source, target, data}) {
const templateFile = path.join(__dirname, `template/${source}`);
const templateFile = path.join(dirname, `template/${source}`);
const targetFile = path.join(ROOT, target);
const templateContent = fs.readFileSync(templateFile, 'utf8');

Expand Down
10 changes: 6 additions & 4 deletions test/integration/projects.js → test/integration/projects.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';
const path = require('path');
import path from 'node:path';
import {fileURLToPath} from 'node:url';

module.exports = [
const dirname = path.dirname(fileURLToPath(import.meta.url));

export default [
{
name: 'fixtures-local',
location: path.join(__dirname, 'fixtures-local')
location: path.join(dirname, 'fixtures-local')
},
{
repository: 'https://github.com/avajs/ava',
Expand Down
29 changes: 15 additions & 14 deletions test/integration/test.js → test/integration/test.mjs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const Listr = require('listr');
const execa = require('execa');
const chalk = require('chalk');
const {isCI} = require('ci-info');
const mem = require('mem');
const allProjects = require('./projects');

import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import Listr from 'listr';
import execa from 'execa';
import chalk from 'chalk';
import {isCI} from 'ci-info';
import mem from 'mem';
import allProjects from './projects.mjs';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const projectsArguments = process.argv.slice(2);
const projects = projectsArguments.length === 0 ?
allProjects :
Expand All @@ -35,7 +36,7 @@ const makeEslintTask = (project, destination) => {
'--format',
'json',
'--config',
path.join(__dirname, 'config.js')
path.join(dirname, 'config.js')
];

for (const pattern of project.ignore) {
Expand All @@ -46,7 +47,7 @@ const makeEslintTask = (project, destination) => {
let stdout;
let processError;
try {
({stdout} = await execa('npx', arguments_, {cwd: destination, localDir: __dirname}));
({stdout} = await execa('npx', arguments_, {cwd: destination, localDir: dirname}));
} catch (error) {
({stdout} = error);
processError = error;
Expand Down Expand Up @@ -89,7 +90,7 @@ const makeEslintTask = (project, destination) => {
const getBranch = mem(async dirname => (await execa('git', ['branch', '--show-current'], {cwd: dirname})).stdout);

const execute = project => {
const destination = project.location || path.join(__dirname, 'fixtures', project.name);
const destination = project.location || path.join(dirname, 'fixtures', project.name);

return new Listr([
{
Expand Down Expand Up @@ -120,7 +121,7 @@ const execute = project => {
const list = new Listr([
{
title: 'Setup',
task: () => execa('npm', ['install'], {cwd: __dirname})
task: () => execa('npm', ['install'], {cwd: dirname})
},
{
title: 'Integration tests',
Expand Down
6 changes: 2 additions & 4 deletions test/run-rules-on-codebase/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ const eslint = new ESLint({
// ESLint don't support module
'rules/**/*.js',
'index.js',
'test/integration/config.js',
// `eslint-remote-tester` only support cjs config
'test/smoke/eslint-remote-tester.config.js',
// TODO: Switch to module
'scripts/create-rule.js',
'test/integration/**/*'
'test/smoke/eslint-remote-tester.config.js'
],
rules: {
'unicorn/prefer-module': 'off'
Expand Down

0 comments on commit f1f30c3

Please sign in to comment.