Skip to content

Commit 8fb6180

Browse files
authored
chore: use vscode.glob instead of glob (#77)
1 parent 2ae57be commit 8fb6180

6 files changed

Lines changed: 40 additions & 280 deletions

File tree

e2e/wdio.conf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export function createBaseConfig(workspacePath: string, userSettings = {}): Webd
8383
if (process.platform === 'linux') {
8484
const result = shell.exec('xdotool search --onlyvisible --name code')
8585
const windowId = result.stdout.trim()
86-
shell.exec(`xdotool windowmove ${windowId} 0 0`)
87-
shell.exec(`xdotool windowsize ${windowId} 100% 100%`)
86+
shell.exec(`xdotool windowmove ${windowId} 0 0`, { silent: true })
87+
shell.exec(`xdotool windowsize ${windowId} 100% 100%`, { silent: true })
8888
}
8989
},
9090
afterTest: async function (_test: unknown, _context: unknown, result: Frameworks.TestResult) {

packages/vscode-wdio-config/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"dependencies": {
1818
"@vscode-wdio/constants": "workspace:*",
1919
"@vscode-wdio/logger": "workspace:*",
20-
"@vscode-wdio/utils": "workspace:*",
21-
"glob": "^11.0.1"
20+
"@vscode-wdio/utils": "workspace:*"
2221
},
2322
"devDependencies": {
2423
"@vscode-wdio/types": "workspace:*"

packages/vscode-wdio-config/src/find.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import fs from 'node:fs/promises'
2-
import path from 'node:path'
32

43
import { log } from '@vscode-wdio/logger'
54
import { normalizePath } from '@vscode-wdio/utils'
6-
import { glob } from 'glob'
5+
import * as vscode from 'vscode'
76

87
export async function findWdioConfig(workSpaceRoot: string, configFilePattern: string[]) {
98
log.debug(`Target workspace path: ${workSpaceRoot}`)
109
log.debug(`Detecting the configuration file for WebdriverIO...: ${configFilePattern.join(', ')}`)
10+
const globResult = await Promise.all(
11+
configFilePattern.map((p) =>
12+
vscode.workspace.findFiles(new vscode.RelativePattern(workSpaceRoot, p), '**/node_modules/**')
13+
)
14+
)
1115

12-
const wdioConfigPaths = await glob(configFilePattern, {
13-
cwd: workSpaceRoot,
14-
withFileTypes: false,
15-
ignore: '**/node_modules/**',
16-
})
16+
const wdioConfigPaths = globResult.flatMap((uri) => uri).map((uri) => uri.fsPath)
1717

1818
const configs = (
1919
await Promise.all(
20-
wdioConfigPaths.map(async (_wdioConfigPath) => {
21-
const wdioConfigPath = path.join(workSpaceRoot, _wdioConfigPath)
20+
wdioConfigPaths.map(async (wdioConfigPath) => {
2221
log.debug(`Checking the path: ${wdioConfigPath}`)
2322
try {
2423
await fs.access(wdioConfigPath, fs.constants.R_OK)
Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import fs from 'node:fs/promises'
22
import path from 'node:path'
33

4-
import { glob } from 'glob'
54
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
5+
import * as vscode from 'vscode'
66

77
import { findWdioConfig } from '../src/find.js'
88

99
// Mock dependencies
1010
vi.mock('node:fs/promises')
1111
vi.mock('glob')
1212

13-
vi.mock('vscode', async () => import('../../../tests/__mocks__/vscode.cjs'))
13+
vi.mock('vscode', async () => {
14+
const vscode = await import('../../../tests/__mocks__/vscode.cjs')
15+
return {
16+
...vscode,
17+
RelativePattern: vi.fn(),
18+
workspace: {
19+
findFiles: vi.fn(),
20+
},
21+
}
22+
})
1423
vi.mock('@vscode-wdio/logger', () => import('../../../tests/__mocks__/logger.js'))
1524

1625
describe('findWdioConfig', () => {
@@ -19,6 +28,13 @@ describe('findWdioConfig', () => {
1928

2029
beforeEach(() => {
2130
vi.resetAllMocks()
31+
vi.mocked(vscode.RelativePattern).mockImplementation(function (this: any, r: unknown, p: string) {
32+
this.path = p
33+
this.root = r
34+
this.toString = function () {
35+
return path.join(this.root, this.path)
36+
}
37+
} as any)
2238
})
2339

2440
afterEach(() => {
@@ -30,9 +46,9 @@ describe('findWdioConfig', () => {
3046
const mockConfigFiles = ['wdio.conf.js', 'wdio.conf.ts']
3147
const expectedPaths = mockConfigFiles.map((file) => path.join(mockWorkspaceRoot, file))
3248

33-
// Mock glob to return the config files
34-
vi.mocked(glob).mockResolvedValue(mockConfigFiles)
35-
49+
vi.mocked(vscode.workspace.findFiles).mockImplementation(async (p: vscode.GlobPattern) => {
50+
return [vscode.Uri.file(p.toString())]
51+
})
3652
// Mock fs.access to succeed for all files
3753
vi.mocked(fs.access).mockResolvedValue(undefined)
3854

@@ -41,21 +57,16 @@ describe('findWdioConfig', () => {
4157

4258
// Verify
4359
expect(result).toEqual(expectedPaths)
44-
expect(glob).toHaveBeenCalledWith(defaultConfigFilePattern, {
45-
cwd: mockWorkspaceRoot,
46-
withFileTypes: false,
47-
ignore: '**/node_modules/**',
48-
})
4960
expect(fs.access).toHaveBeenCalledTimes(2)
5061
})
5162

5263
it('should filter out inaccessible files', async () => {
5364
// Setup
54-
const mockConfigFiles = ['wdio.conf.js', 'wdio.conf.ts']
5565
const accessibleFile = path.join(mockWorkspaceRoot, 'wdio.conf.js')
5666

57-
// Mock glob to return the config files
58-
vi.mocked(glob).mockResolvedValue(mockConfigFiles)
67+
vi.mocked(vscode.workspace.findFiles).mockImplementation(async (p: vscode.GlobPattern) => {
68+
return [vscode.Uri.file(p.toString())]
69+
})
5970

6071
// Mock fs.access to succeed only for the JS file
6172
vi.mocked(fs.access).mockImplementation(async (filePath) => {
@@ -75,10 +86,9 @@ describe('findWdioConfig', () => {
7586

7687
it('should return empty array when no config files are accessible', async () => {
7788
// Setup
78-
const mockConfigFiles = ['wdio.conf.js', 'wdio.conf.ts']
79-
80-
// Mock glob to return the config files
81-
vi.mocked(glob).mockResolvedValue(mockConfigFiles)
89+
vi.mocked(vscode.workspace.findFiles).mockImplementation(async (p: vscode.GlobPattern) => {
90+
return [vscode.Uri.file(p.toString())]
91+
})
8292

8393
// Mock fs.access to fail for all files
8494
vi.mocked(fs.access).mockRejectedValue(new Error('File not found'))
@@ -93,8 +103,7 @@ describe('findWdioConfig', () => {
93103

94104
it('should handle empty glob results', async () => {
95105
// Setup
96-
// Mock glob to return no files
97-
vi.mocked(glob).mockResolvedValue([])
106+
vi.mocked(vscode.workspace.findFiles).mockResolvedValue([])
98107

99108
// Execute
100109
const result = await findWdioConfig(mockWorkspaceRoot, defaultConfigFilePattern)
@@ -103,28 +112,4 @@ describe('findWdioConfig', () => {
103112
expect(result).toEqual([])
104113
expect(fs.access).not.toHaveBeenCalled()
105114
})
106-
107-
it('should use custom config file pattern when provided', async () => {
108-
// Setup
109-
const customConfigPattern = ['custom.wdio.conf.js']
110-
const mockConfigFiles = ['custom.wdio.conf.js']
111-
const expectedPaths = mockConfigFiles.map((file) => path.join(mockWorkspaceRoot, file))
112-
113-
// Mock glob to return the config files
114-
vi.mocked(glob).mockResolvedValue(mockConfigFiles)
115-
116-
// Mock fs.access to succeed
117-
vi.mocked(fs.access).mockResolvedValue(undefined)
118-
119-
// Execute
120-
const result = await findWdioConfig(mockWorkspaceRoot, customConfigPattern)
121-
122-
// Verify
123-
expect(result).toEqual(expectedPaths)
124-
expect(glob).toHaveBeenCalledWith(customConfigPattern, {
125-
cwd: mockWorkspaceRoot,
126-
withFileTypes: false,
127-
ignore: '**/node_modules/**',
128-
})
129-
})
130115
})

0 commit comments

Comments
 (0)