Skip to content

Commit 4eba2cb

Browse files
Merge pull request #217 from beakerandjake/feature/216-fix-input-file-trimmed
Feature/216 fix input file trimmed
2 parents 1a7eb4d + 83ed562 commit 4eba2cb

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- `downloadInput()` no longer trims the start of the text ([#216](https://github.com/beakerandjake/advent-of-code-runner/issues/216))
12+
1013
## [1.3.3] - 2023-02-09
1114
### Fixed
1215
- Removed WIP warning message on README

src/api/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const downloadInput = async (year, day, authenticationToken) => {
5353
}
5454

5555
// expect text of response is the input.
56-
const text = (await response.text())?.trim() || '';
56+
const text = (await response.text())?.trimEnd() || '';
5757
logger.debug('downloaded: %s', sizeOfStringInKb(text));
5858

5959
if (!text) {

tests/api/api.test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,35 @@ describe('api', () => {
9898
const result = await downloadInput(2022, 1, 'ASDF');
9999
expect(result).toBe(expected);
100100
});
101+
102+
test('does not trim start of input', async () => {
103+
const expected = '\t1234\n5678\n9101112';
104+
mockFetch.mockImplementation(() =>
105+
Promise.resolve({
106+
ok: true,
107+
status: 200,
108+
text: () => Promise.resolve(expected),
109+
})
110+
);
111+
const result = await downloadInput(2022, 1, 'ASDF');
112+
expect(result).toBe(expected);
113+
});
114+
115+
test('trims end of input', async () => {
116+
const expected = '1234\n5678\n9101112';
117+
mockFetch.mockImplementation(() =>
118+
Promise.resolve({
119+
ok: true,
120+
status: 200,
121+
text: () => Promise.resolve(`${expected}\t\n`),
122+
})
123+
);
124+
const result = await downloadInput(2022, 1, 'ASDF');
125+
expect(result).toBe(expected);
126+
});
101127
});
102128

103-
describe('submitSolution', () => {
129+
describe('submitSolution()', () => {
104130
test.each([undefined, null, ''])(
105131
'throws if authentication token is: "%s"',
106132
async (value) => {

0 commit comments

Comments
 (0)