rewritte of test
This commit is contained in:
parent
f1ee23f5fa
commit
6e021788e1
36 changed files with 382 additions and 687 deletions
41
Integration/fs-module/script.js
Normal file
41
Integration/fs-module/script.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Test file path
|
||||
const testFile = path.join(__dirname, 'test-file.txt');
|
||||
|
||||
try {
|
||||
// Step 1: Write to a file
|
||||
console.log('Writing to file...');
|
||||
const data = 'Hello, TMT fs test!';
|
||||
fs.writeFileSync(testFile, data);
|
||||
if (fs.existsSync(testFile)) {
|
||||
console.log('✔ File created successfully.');
|
||||
} else {
|
||||
throw new Error('✘ Failed to create file.');
|
||||
}
|
||||
|
||||
// Step 2: Read from the file
|
||||
console.log('Reading from file...');
|
||||
const fileContent = fs.readFileSync(testFile, 'utf8');
|
||||
if (fileContent === data) {
|
||||
console.log('✔ File content matches expected.');
|
||||
} else {
|
||||
throw new Error('✘ File content mismatch.');
|
||||
}
|
||||
|
||||
// Step 3: Delete the file
|
||||
console.log('Deleting file...');
|
||||
fs.unlinkSync(testFile);
|
||||
if (!fs.existsSync(testFile)) {
|
||||
console.log('✔ File deleted successfully.');
|
||||
} else {
|
||||
throw new Error('✘ Failed to delete file.');
|
||||
}
|
||||
|
||||
console.log('All tests passed!');
|
||||
process.exit(0); // Success exit code
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
process.exit(1); // Failure exit code
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue