-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(exec): Include nested scripts in --list (#11262)
- Loading branch information
Showing
6 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- fix(exec): Include nested scripts in --list (#11262) by @Tobbe | ||
|
||
Now also nested scripts, like `scripts/nested/script.ts`, are included in the | ||
output of `yarn rw exec --list` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async () => { | ||
console.log('Hello from myNestedScript.ts') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import path from 'node:path' | ||
|
||
import '../../lib/mockTelemetry' | ||
|
||
import { vi, afterEach, beforeEach, describe, it, expect } from 'vitest' | ||
|
||
import { handler } from '../execHandler' | ||
|
||
vi.mock('envinfo', () => ({ default: { run: () => '' } })) | ||
vi.mock('@redwoodjs/project-config', () => ({ | ||
getPaths: () => ({ | ||
scripts: path.join( | ||
__dirname, | ||
'../../../../../__fixtures__/test-project/scripts', | ||
), | ||
}), | ||
resolveFile: (path: string) => path, | ||
})) | ||
|
||
const mockRedwoodToml = { | ||
fileContents: '', | ||
} | ||
|
||
// Before rw tests run, api/ and web/ `jest.config.js` is confirmed via existsSync() | ||
vi.mock('node:fs', async () => ({ | ||
default: { | ||
readFileSync: () => { | ||
return mockRedwoodToml.fileContents | ||
}, | ||
}, | ||
})) | ||
|
||
beforeEach(() => { | ||
vi.spyOn(console, 'log').mockImplementation(() => {}) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.mocked(console).log.mockRestore() | ||
}) | ||
|
||
describe('yarn rw exec --list', () => { | ||
it('includes nested scripts', async () => { | ||
await handler({ list: true }) | ||
const scriptPath = path | ||
.join('one', 'two', 'myNestedScript') | ||
// Handle Windows path separators | ||
.replaceAll('\\', '\\\\') | ||
expect(vi.mocked(console).log).toHaveBeenCalledWith( | ||
expect.stringMatching(new RegExp('\\b' + scriptPath + '\\b')), | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters