Skip to content

Commit 5453bff

Browse files
authored
Merge pull request #1128 from nextcloud-libraries/fix/testing-globs
fix(globs): adjust globs for test related files
2 parents ac38dd0 + bedbd7f commit 5453bff

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

lib/globs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export const GLOB_FILES_TESTING = [
88
'**/*.test.*',
99
'**/*.spec.*',
1010
'**/*.cy.*',
11-
'**/test',
12-
'**/tests',
11+
'**/test/**',
12+
'**/tests/**',
13+
'**/__tests__/**',
14+
'**/__mocks__/**',
1315
]
1416

1517
/** Glob pattern for Typescript files */

tests/config-codestyle.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import type { Linter } from 'eslint'
66

77
import { ESLint } from 'eslint'
8+
import { existsSync } from 'fs'
9+
import { readFile } from 'fs/promises'
810
import { join, resolve } from 'path'
911
import { expect, test } from 'vitest'
1012
import * as eslintConfig from '../lib/index.js'
@@ -21,9 +23,18 @@ const eslint = new ESLint({
2123
* @param file - File path to lint
2224
* @return Lint result
2325
*/
24-
async function lintFile(file) {
25-
const real = resolve(join(__dirname, file))
26-
return await eslint.lintFiles(real)
26+
async function lintTestCase(testCase: string) {
27+
let file = `fixtures/codestyle/input/${testCase}.`
28+
if (existsSync(join(__dirname, file) + 'js')) {
29+
file += 'js'
30+
} else {
31+
file += 'ts'
32+
}
33+
34+
const path = resolve(join(__dirname, file))
35+
const content = await readFile(path)
36+
const results = await eslint.lintText(content.toString(), { filePath: `src/${file}` })
37+
return { results, path }
2738
}
2839

2940
test.for([
@@ -37,7 +48,7 @@ test.for([
3748
'quotes',
3849
'semicolons',
3950
])('Code style', async (testCase: string) => {
40-
const results = await lintFile(`fixtures/codestyle/input/${testCase}.{t,j}s`)
51+
const { results, path } = await lintTestCase(testCase)
4152
expect(results).toHaveLength(1)
42-
await expect(results[0].output).toMatchFileSnapshot(results[0].filePath.replace('input', 'output'))
53+
await expect(results[0].output).toMatchFileSnapshot(path.replace('input', 'output'))
4354
})

tests/config-javascript.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import type { Linter } from 'eslint'
66

77
import { ESLint } from 'eslint'
8-
import { access, copyFile, rm } from 'fs/promises'
8+
import { access, copyFile, readFile, rm } from 'fs/promises'
99
import { join, resolve } from 'path'
1010
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
1111
import * as eslintConfig from '../lib/index.js'
@@ -21,9 +21,10 @@ const eslint = new ESLint({
2121
* @param file - File path to lint
2222
* @return Lint result
2323
*/
24-
async function lintFile(file) {
24+
async function lintFile(file: string) {
2525
const real = resolve(join(__dirname, file))
26-
return await eslint.lintFiles(real)
26+
const content = await readFile(real)
27+
return await eslint.lintText(content.toString(), { filePath: join('src', file) })
2728
}
2829

2930
test('some basic issues should fail', async () => {

tests/config-typescript.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type { Linter } from 'eslint'
66

77
import { ESLint } from 'eslint'
8+
import { readFile } from 'fs/promises'
89
import { join, resolve } from 'path'
910
import { describe, expect, test } from 'vitest'
1011
import * as eslintConfig from '../lib/index.js'
@@ -17,7 +18,8 @@ const eslint = new ESLint({
1718
describe('Typescript', () => {
1819
async function lintFile(file: string) {
1920
const real = resolve(join(__dirname, file))
20-
return await eslint.lintFiles(real)
21+
const content = await readFile(real)
22+
return await eslint.lintText(content.toString(), { filePath: join('src', file) })
2123
}
2224

2325
// Vue files can be both Javascript and Typescript

0 commit comments

Comments
 (0)