Skip to content

Commit

Permalink
Refactor replaceBackslashes() test utility to migrate to ESM (#7034)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Jul 3, 2023
1 parent 15c15b6 commit 74c90b3
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/__tests__/cli.test.mjs
Expand Up @@ -8,7 +8,7 @@ import { jest } from '@jest/globals';
import stripAnsi from 'strip-ansi';

import readJSONFile from '../testUtils/readJSONFile.mjs';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';

import cli from '../cli.js';

Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/ignore.test.mjs
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';

import AllFilesIgnoredError from '../utils/allFilesIgnoredError.js';
import NoFilesFoundError from '../utils/noFilesFoundError.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import safeChdir from '../testUtils/safeChdir.mjs';
import standalone from '../standalone.js';

Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/invalidScopeDisables.test.mjs
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { stripIndent } from 'common-tags';

import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import standalone from '../standalone.js';

function fixture(name) {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/needlessDisables.test.mjs
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { stripIndent } from 'common-tags';

import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import standalone from '../standalone.js';

function fixture(name) {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/printConfig.test.mjs
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url';
import pluginWarnAboutFoo from './fixtures/plugin-warn-about-foo.js';
import printConfig from '../printConfig.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';

it('printConfig uses getConfigForFile to retrieve the config', async () => {
const filepath = replaceBackslashes(
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/resolveConfig.test.mjs
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import pluginWarnAboutFoo from './fixtures/plugin-warn-about-foo.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import stylelint from '../index.js';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-cache.test.mjs
Expand Up @@ -6,7 +6,7 @@ import path from 'node:path';
import fCache from 'file-entry-cache';

import hash from '../utils/hash.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import safeChdir from '../testUtils/safeChdir.mjs';
import standalone from '../standalone.js';

Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-fix.test.mjs
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path';

import { stripIndent, stripIndents } from 'common-tags';

import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import safeChdir from '../testUtils/safeChdir.mjs';
import standalone from '../standalone.js';
import uniqueId from '../testUtils/uniqueId.mjs';
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-globs.test.mjs
@@ -1,6 +1,6 @@
import path from 'node:path';

import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import standalone from '../standalone.js';

const fixturesPath = replaceBackslashes(new URL('./fixtures/globs', import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-maxWarnings.test.mjs
@@ -1,5 +1,5 @@
import path from 'node:path';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import standalone from '../standalone.js';

const fixturesPath = replaceBackslashes(new URL('./fixtures', import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-parseErrors.test.mjs
Expand Up @@ -2,7 +2,7 @@ import { createRequire } from 'node:module';
import { jest } from '@jest/globals';

import readJSONFile from '../testUtils/readJSONFile.mjs';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import standalone from '../standalone.js';

const configBlockNoEmpty = readJSONFile(
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-syntax.test.mjs
Expand Up @@ -3,7 +3,7 @@ import { writeFile } from 'node:fs/promises';

import { jest } from '@jest/globals';

import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import standalone from '../standalone.js';
import stringFormatter from '../formatters/stringFormatter.js';

Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/standalone.test.mjs
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';

import NoFilesFoundError from '../utils/noFilesFoundError.js';
import readJSONFile from '../testUtils/readJSONFile.mjs';
import replaceBackslashes from '../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';
import safeChdir from '../testUtils/safeChdir.mjs';
import standalone from '../standalone.js';

Expand Down
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url';
import path from 'node:path';

import replaceBackslashes from '../../testUtils/replaceBackslashes.js';
import replaceBackslashes from '../../testUtils/replaceBackslashes.mjs';
import safeChdir from '../../testUtils/safeChdir.mjs';
import standalone from '../../standalone.js';

Expand Down
@@ -1,11 +1,9 @@
'use strict';

const { fileURLToPath } = require('node:url');
import { fileURLToPath } from 'node:url';

/**
* @param {string | URL} path
* @returns {string}
*/
module.exports = function replaceBackslashes(path) {
export default function replaceBackslashes(path) {
return (typeof path === 'string' ? path : fileURLToPath(path)).replace(/\\/g, '/');
};
}
2 changes: 1 addition & 1 deletion system-tests/systemTestUtils.mjs
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
import os from 'node:os';
import path from 'node:path';

import replaceBackslashes from '../lib/testUtils/replaceBackslashes.js';
import replaceBackslashes from '../lib/testUtils/replaceBackslashes.mjs';
import uniqueId from '../lib/testUtils/uniqueId.mjs';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
Expand Down

0 comments on commit 74c90b3

Please sign in to comment.