Skip to content

Commit 80c3244

Browse files
committed
chore: debug test
1 parent 0d66923 commit 80c3244

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

scripts/setup-tests.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
3-
import tempDir from 'temp-dir';
3+
import os from 'node:os';
44
import {$} from 'execa';
55
import {pathExists} from 'path-exists';
66

7+
const temporaryDir = os.tmpdir();
8+
79
/**
810
Creates a test project with a package.json and tsconfig.json and installs the dependencies.
911
1012
@returns {string} The path to the test project.
1113
*/
12-
const cwd = path.join(tempDir, 'test-project');
14+
const cwd = path.join(temporaryDir, 'test-project');
1315

1416
if (await pathExists(cwd)) {
1517
await fs.rm(cwd, {recursive: true, force: true});
@@ -34,7 +36,7 @@ await fs.writeFile(
3436
compilerOptions: {
3537
module: 'node16',
3638
target: 'ES2022',
37-
strictNullChecks: true,
39+
strict: true,
3840
lib: ['DOM', 'DOM.Iterable', 'ES2022'],
3941
},
4042
files: [path.join(cwd, 'test.ts')],
@@ -47,4 +49,4 @@ await fs.writeFile(
4749
await $({
4850
cwd,
4951
stdio: 'inherit',
50-
})`npm install --save-dev typescript @types/node @sindresorhus/tsconfig`;
52+
})`npm install --save-dev typescript @types/node`;

test/helpers/copy-test-project.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
3+
import os from 'node:os';
34
import {randomUUID} from 'node:crypto';
4-
import tempDir from 'temp-dir';
55
import {pathExists} from 'path-exists';
66

7+
const temporaryDir = os.tmpdir();
8+
79
/**
810
Copies the test project in the temp directory to a new directory.
911
1012
@returns {string} The path to the copied test project.
1113
*/
1214
export const copyTestProject = async () => {
13-
if (!(await pathExists(tempDir))) {
15+
if (!(await pathExists(temporaryDir))) {
1416
throw new Error('temp-dir/test-project does not exist');
1517
}
1618

17-
const testCwd = path.join(tempDir, 'test-project');
18-
const newCwd = path.join(tempDir, randomUUID());
19+
const testCwd = path.join(temporaryDir, 'test-project');
20+
const newCwd = path.join(temporaryDir, randomUUID());
1921

2022
await fs.cp(testCwd, newCwd, {recursive: true});
2123

@@ -26,7 +28,7 @@ export const copyTestProject = async () => {
2628
compilerOptions: {
2729
module: 'node16',
2830
target: 'ES2022',
29-
strictNullChecks: true,
31+
strict: true,
3032
lib: ['DOM', 'DOM.Iterable', 'ES2022'],
3133
},
3234
files: [path.join(newCwd, 'test.ts')],

test/xo/lint-text.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ test('plugin > ts > eslint-plugin-eslint-comments no-duplicate-disable', async t
368368

369369
test('lint-text can be ran multiple times in a row with top level typescript rules', async t => {
370370
const {cwd} = t.context;
371-
const tsFilePath = path.join(cwd, 'test.ts');
371+
const filePath = path.join(cwd, 'test.ts');
372372
// Text should violate the @typescript-eslint/naming-convention rule
373373
const text = dedent`
374374
const fooBar = 10;
@@ -377,12 +377,11 @@ test('lint-text can be ran multiple times in a row with top level typescript rul
377377
const foo_bar = 10;\n
378378
`;
379379

380-
const {results: resultsNoConfig} = await new Xo({cwd}).lintText(
381-
text,
382-
{filePath: tsFilePath},
383-
);
380+
const {results: resultsNoConfig} = await Xo.lintText(text, {cwd, filePath});
384381
// Ensure that with no config, the text is linted and errors are found
385-
t.true(resultsNoConfig[0]?.errorCount === 3);
382+
// t.true(resultsNoConfig[0]?.errorCount === 3);
383+
384+
t.log(resultsNoConfig[0]);
386385

387386
await fs.writeFile(
388387
path.join(cwd, 'xo.config.ts'),
@@ -399,15 +398,20 @@ test('lint-text can be ran multiple times in a row with top level typescript rul
399398
'utf8',
400399
);
401400

401+
t.log(await fs.readFile(path.join(cwd, 'tsconfig.json'), 'utf8'));
402+
402403
// Now with a config that turns off the naming-convention rule, the text should not have any errors
403404
// and should not have any messages when ran multiple times
404-
const {results} = await Xo.lintText(text, {cwd, filePath: tsFilePath, warnIgnored: false});
405+
const {results} = await Xo.lintText(text, {cwd, filePath});
406+
t.log(results[0]);
405407
t.is(results[0]?.errorCount, 0);
406408
t.true(results[0]?.messages?.length === 0);
407-
const {results: results2} = await Xo.lintText(text, {cwd, filePath: tsFilePath, warnIgnored: false});
409+
const {results: results2} = await Xo.lintText(text, {cwd, filePath});
410+
t.log(results2[0]);
408411
t.is(results2[0]?.errorCount, 0);
409412
t.true(results2[0]?.messages?.length === 0);
410-
const {results: results3} = await Xo.lintText(text, {cwd, filePath: tsFilePath, warnIgnored: false});
413+
const {results: results3} = await Xo.lintText(text, {cwd, filePath});
414+
t.log(results3[0]);
411415
t.is(results3[0]?.errorCount, 0);
412416
t.true(results3[0]?.messages?.length === 0);
413417
});

0 commit comments

Comments
 (0)