-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(watch): --include
& --exclude
CLI flags
#561
Changes from all commits
b0156f6
090ca0b
0bf0d44
d75a62b
e658acf
350acc5
9327d90
9c26cf6
94db887
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -300,5 +300,59 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { | |||||
expect(p.stderr).toBe(''); | ||||||
}, 10_000); | ||||||
}); | ||||||
|
||||||
describe('include', ({ test }) => { | ||||||
test('watch files for changes', async () => { | ||||||
const entryFile = 'index.js'; | ||||||
const file = 'file'; | ||||||
const value = 'test'; | ||||||
const append = `${value}append`; | ||||||
const fixture = await createFixture({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the |
||||||
[entryFile]: ` | ||||||
import fs from 'fs'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
fs.readFile('./${file}', (err, data) => { | ||||||
if (!err) { | ||||||
console.log(data.toString()); | ||||||
} else { | ||||||
console.log(error); | ||||||
} | ||||||
}); | ||||||
`.trim(), | ||||||
[file]: `${value}`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
const tsxProcess = tsx({ | ||||||
cwd: fixture.path, | ||||||
args: [ | ||||||
'watch', | ||||||
'--clear-screen=false', | ||||||
`--include=${file}`, | ||||||
entryFile, | ||||||
], | ||||||
}); | ||||||
|
||||||
tsxProcess.stdout?.on('data', async (data: Buffer) => { | ||||||
const chunkString = data.toString(); | ||||||
if (chunkString === `${value}\n`) { | ||||||
await fixture.writeFile(file, `${append}`); | ||||||
} | ||||||
|
||||||
if (chunkString === `${append}\n`) { | ||||||
await setTimeout(500); | ||||||
await fixture.writeFile(entryFile, 'console.log("TERMINATE")'); | ||||||
} | ||||||
|
||||||
if (chunkString === 'TERMINATE\n') { | ||||||
tsxProcess.kill(); | ||||||
} | ||||||
}); | ||||||
|
||||||
const tsxProcessResolved = await tsxProcess; | ||||||
await fixture.rm(); | ||||||
|
||||||
expect(tsxProcessResolved.stdout).not.toMatch(`current date: ${value}`); | ||||||
expect(tsxProcessResolved.stderr).toBe(''); | ||||||
}, 10_000); | ||||||
}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for |
||||||
}); | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you're trying to couple these together via variables but I think the test will be much more readable if you just hard-code them