Skip to content

Commit

Permalink
fix: automatically handle absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eddienubes committed Aug 24, 2024
1 parent f257d79 commit 32366d7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Sage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { FormDataOptions } from './FormDataOptions.js';
import { createReadStream } from 'node:fs';
import { SageConfig } from './SageConfig.js';
import { SageServer } from './SageServer.js';
import fs from 'node:fs/promises';

Check warning on line 27 in src/Sage.ts

View workflow job for this annotation

GitHub Actions / CI (20.x)

'fs' is defined but never used

Check warning on line 27 in src/Sage.ts

View workflow job for this annotation

GitHub Actions / CI (18.x)

'fs' is defined but never used

Check warning on line 27 in src/Sage.ts

View workflow job for this annotation

GitHub Actions / CI / CI (20.x)

'fs' is defined but never used

Check warning on line 27 in src/Sage.ts

View workflow job for this annotation

GitHub Actions / CI / CI (18.x)

'fs' is defined but never used

Check warning on line 27 in src/Sage.ts

View workflow job for this annotation

GitHub Actions / CI / CI (18.x)

'fs' is defined but never used

Check warning on line 27 in src/Sage.ts

View workflow job for this annotation

GitHub Actions / CI / CI (20.x)

'fs' is defined but never used

/**
* Greetings, I'm Sage - a chainable HTTP Testing Assistant.
Expand Down Expand Up @@ -180,7 +181,7 @@ export class Sage {
* If file is a string, it will be treated as a path to a file starting from the working directory (process.cwd()).
* @throws SageException if body is already set
* @param field
* @param file a Blob, Buffer, Readable stream or a file path (staring from the working directory)
* @param file a Blob, Buffer, Readable stream or a file path either staring from the working directory, or an absolute path
* @param options you can pass either object with type and filename or just a string with filename
*/
attach(
Expand All @@ -199,7 +200,9 @@ export class Sage {

// If a string always treat it as a file path
if (typeof file === 'string') {
file = createReadStream(path.join(process.cwd(), file));
file = path.isAbsolute(file) ? file : path.join(process.cwd(), file);

file = createReadStream(file);
}

if (typeof options === 'string') {
Expand Down

0 comments on commit 32366d7

Please sign in to comment.