diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f46b2d3..5426e5b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -17,7 +17,3 @@ updates: patterns: - '@types/lodash-es' - 'lodash-es' - vitest: - patterns: - - '@vitest/*' - - 'vitest' diff --git a/2015/day/12/index.test.ts b/2015/day/12/index.test.ts index 994a1a9..e62b60e 100644 --- a/2015/day/12/index.test.ts +++ b/2015/day/12/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = await readFile(`${import.meta.dirname}/input`, 'utf-8'); +const input = await getInput(import.meta.dirname); describe('Day 12', () => { describe('Part 1', () => { diff --git a/2015/day/14/index.test.ts b/2015/day/14/index.test.ts index 5c579c9..069cbb6 100644 --- a/2015/day/14/index.test.ts +++ b/2015/day/14/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 14', () => { describe('Part 1', () => { diff --git a/2015/day/16/index.test.ts b/2015/day/16/index.test.ts index 20472b8..170a85a 100644 --- a/2015/day/16/index.test.ts +++ b/2015/day/16/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 16', () => { describe('Part 1', () => { diff --git a/2016/day/1/index.test.ts b/2016/day/1/index.test.ts index a6e9622..a5d5b9f 100644 --- a/2016/day/1/index.test.ts +++ b/2016/day/1/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split(', '); +const input = (await getInput(import.meta.dirname)).split(', '); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2016/day/2/index.test.ts b/2016/day/2/index.test.ts index 300287e..a3e4d4e 100644 --- a/2016/day/2/index.test.ts +++ b/2016/day/2/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); -const inputSample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); +const inputSample = (await getInputSample(import.meta.dirname)).split('\n'); describe('Day 2', () => { describe('Part 1', () => { diff --git a/2016/day/3/index.test.ts b/2016/day/3/index.test.ts index c95e314..f683d64 100644 --- a/2016/day/3/index.test.ts +++ b/2016/day/3/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('2016 Day 3', () => { describe('Part 1', () => { diff --git a/2016/day/4/index.test.ts b/2016/day/4/index.test.ts index 0434c71..e36af95 100644 --- a/2016/day/4/index.test.ts +++ b/2016/day/4/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('2016 Day 3', () => { describe('Part 1', () => { diff --git a/2016/day/6/input.test.ts b/2016/day/6/input.test.ts index 3b83b1b..b1494eb 100644 --- a/2016/day/6/input.test.ts +++ b/2016/day/6/input.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); -const inputSample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); +const inputSample = (await getInputSample(import.meta.dirname)).split('\n'); describe('2016 Day 6', () => { describe('Part 1', () => { diff --git a/2017/day/1/index.test.ts b/2017/day/1/index.test.ts index 3ffc4e3..007feab 100644 --- a/2017/day/1/index.test.ts +++ b/2017/day/1/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('').map(Number); +const input = (await getInput(import.meta.dirname)).split('').map(Number); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2017/day/2/index.test.ts b/2017/day/2/index.test.ts index ed0eb69..1d52b8e 100644 --- a/2017/day/2/index.test.ts +++ b/2017/day/2/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')) +const input = (await getInput(import.meta.dirname)) .split('\n') .map((row) => row.split('\t').map(Number)); diff --git a/2017/day/4/index.test.ts b/2017/day/4/index.test.ts index 145d918..19eb221 100644 --- a/2017/day/4/index.test.ts +++ b/2017/day/4/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 4', () => { describe('Part 1', () => { diff --git a/2018/day/1/index.test.ts b/2018/day/1/index.test.ts index 41458cd..5eed45f 100644 --- a/2018/day/1/index.test.ts +++ b/2018/day/1/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); describe('day-01', () => { describe('Part 1', () => { diff --git a/2018/day/2/index.test.ts b/2018/day/2/index.test.ts index 022265e..2025081 100644 --- a/2018/day/2/index.test.ts +++ b/2018/day/2/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 2', () => { describe('Part 1', () => { diff --git a/2018/day/3/index.test.ts b/2018/day/3/index.test.ts index 9d19d32..858e76e 100644 --- a/2018/day/3/index.test.ts +++ b/2018/day/3/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); -const inputSample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); +const inputSample = (await getInputSample(import.meta.dirname)).split('\n'); describe('Day 3', () => { describe('Part 1', () => { diff --git a/2018/day/5/index.test.ts b/2018/day/5/index.test.ts index 6bd07bf..2789114 100644 --- a/2018/day/5/index.test.ts +++ b/2018/day/5/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = await readFile(`${import.meta.dirname}/input`, 'utf-8'); +const input = await getInput(import.meta.dirname); describe('Day 5', () => { describe('Part 1', () => { diff --git a/2019/day/1/index.test.ts b/2019/day/1/index.test.ts index 5878ef6..2cc5b34 100644 --- a/2019/day/1/index.test.ts +++ b/2019/day/1/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2019/day/2/index.test.ts b/2019/day/2/index.test.ts index 8984669..ec4018e 100644 --- a/2019/day/2/index.test.ts +++ b/2019/day/2/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split(',').map(Number); +const input = (await getInput(import.meta.dirname)).split(',').map(Number); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2019/day/4/index.test.ts b/2019/day/4/index.test.ts index ed25a6d..0bf927a 100644 --- a/2019/day/4/index.test.ts +++ b/2019/day/4/index.test.ts @@ -1,11 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const [lower, upper] = (await readFile(`${import.meta.dirname}/input`, 'utf-8')) - .split('-') - .map(Number); +const [lower, upper] = (await getInput(import.meta.dirname)).split('-').map(Number); describe('Day 4', () => { describe('Part 1', () => { diff --git a/2020/day/1/index.test.ts b/2020/day/1/index.test.ts index 77d1558..9f1618c 100644 --- a/2020/day/1/index.test.ts +++ b/2020/day/1/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2020/day/10/index.test.ts b/2020/day/10/index.test.ts index 26dfdd3..14c0b65 100644 --- a/2020/day/10/index.test.ts +++ b/2020/day/10/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); const exampleInput = [16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4]; const largerExampleInput = [ 28, 33, 18, 42, 31, 14, 46, 20, 48, 47, 24, 23, 49, 45, 19, 38, 39, 11, 1, 32, 25, 35, 8, 17, 7, diff --git a/2020/day/12/index.test.ts b/2020/day/12/index.test.ts index 011b6c9..bc89d07 100644 --- a/2020/day/12/index.test.ts +++ b/2020/day/12/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); const exampleInput = ['F10', 'N3', 'F7', 'R90', 'F11']; describe('Day 12', () => { diff --git a/2020/day/2/index.test.ts b/2020/day/2/index.test.ts index 4c51fa7..39e9f11 100644 --- a/2020/day/2/index.test.ts +++ b/2020/day/2/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2020/day/25/index.test.ts b/2020/day/25/index.test.ts index bfa4ba2..3030512 100644 --- a/2020/day/25/index.test.ts +++ b/2020/day/25/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); describe('Day 25', () => { describe('Part 1', () => { diff --git a/2020/day/3/index.test.ts b/2020/day/3/index.test.ts index 1777ed7..427ef67 100644 --- a/2020/day/3/index.test.ts +++ b/2020/day/3/index.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import type { Slope } from './index.ts'; import { part1, part2 } from './index.ts'; @@ -15,7 +15,7 @@ const exampleInput = `..##.........##.........##.........##.........##.........# #.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#... #...##....##...##....##...##....##...##....##...##....##...##....# .#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#`.split('\n'); -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 3', () => { describe('Part 1', () => { diff --git a/2020/day/4/index.test.ts b/2020/day/4/index.test.ts index fb5baf5..29f4aa4 100644 --- a/2020/day/4/index.test.ts +++ b/2020/day/4/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n\n'); +const input = (await getInput(import.meta.dirname)).split('\n\n'); describe('Day 4', () => { describe('Part 1', () => { diff --git a/2020/day/5/index.test.ts b/2020/day/5/index.test.ts index c0d5a23..1a1fdfe 100644 --- a/2020/day/5/index.test.ts +++ b/2020/day/5/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); describe('Day 5', () => { describe('Part 1', () => { diff --git a/2020/day/6/index.test.ts b/2020/day/6/index.test.ts index cb74a81..1ea49ac 100644 --- a/2020/day/6/index.test.ts +++ b/2020/day/6/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n\n'); -const sampleInput = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n\n'); +const input = (await getInput(import.meta.dirname)).split('\n\n'); +const sampleInput = (await getInputSample(import.meta.dirname)).split('\n\n'); describe('Day 6', () => { describe('Part 1', () => { diff --git a/2020/day/9/index.test.ts b/2020/day/9/index.test.ts index 0c1ffd1..7446376 100644 --- a/2020/day/9/index.test.ts +++ b/2020/day/9/index.test.ts @@ -1,12 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); -const sampleInput = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')) - .split('\n') - .map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); +const sampleInput = (await getInputSample(import.meta.dirname)).split('\n').map(Number); describe('Day 9', () => { describe('Part 1', () => { diff --git a/2021/day/1/index.test.ts b/2021/day/1/index.test.ts index 21dca54..4b0ce66 100644 --- a/2021/day/1/index.test.ts +++ b/2021/day/1/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n').map(Number); +const input = (await getInput(import.meta.dirname)).split('\n').map(Number); const sampleInput = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263]; describe('2021 Day 1', () => { diff --git a/2021/day/2/index.test.ts b/2021/day/2/index.test.ts index 2834ab4..e5abcd6 100644 --- a/2021/day/2/index.test.ts +++ b/2021/day/2/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); const sampleInput = ['forward 5', 'down 5', 'forward 8', 'up 3', 'down 8', 'forward 2']; describe('2021 Day 2', () => { diff --git a/2021/day/3/index.test.ts b/2021/day/3/index.test.ts index a6949c2..f87778d 100644 --- a/2021/day/3/index.test.ts +++ b/2021/day/3/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); const sampleInput = [ '00100', '11110', diff --git a/2022/day/1/index.test.ts b/2022/day/1/index.test.ts index fcb6623..81e8dc6 100644 --- a/2022/day/1/index.test.ts +++ b/2022/day/1/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const sample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n\n'); -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n\n'); +const input = (await getInput(import.meta.dirname)).split('\n\n'); +const sample = (await getInputSample(import.meta.dirname)).split('\n\n'); describe('Day 1', () => { describe('Part 1', () => { diff --git a/2022/day/2/index.test.ts b/2022/day/2/index.test.ts index 6a2062f..1a91a46 100644 --- a/2022/day/2/index.test.ts +++ b/2022/day/2/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const sample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n'); -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); +const sample = (await getInputSample(import.meta.dirname)).split('\n'); describe('Day 2', () => { describe('Part 1', () => { diff --git a/2022/day/3/index.test.ts b/2022/day/3/index.test.ts index 9856b98..fb9bc65 100644 --- a/2022/day/3/index.test.ts +++ b/2022/day/3/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const sample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n'); -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); +const sample = (await getInputSample(import.meta.dirname)).split('\n'); describe('Day 3', () => { describe('Part 1', () => { diff --git a/2022/day/4/index.test.ts b/2022/day/4/index.test.ts index 158ed86..1c7db6e 100644 --- a/2022/day/4/index.test.ts +++ b/2022/day/4/index.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput, getInputSample } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const sample = (await readFile(`${import.meta.dirname}/input.sample`, 'utf-8')).split('\n'); -const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n'); +const input = (await getInput(import.meta.dirname)).split('\n'); +const sample = (await getInputSample(import.meta.dirname)).split('\n'); describe('Day 4', () => { describe('Part 1', () => { diff --git a/2022/day/6/index.test.ts b/2022/day/6/index.test.ts index 8d1fe7a..70ee30d 100644 --- a/2022/day/6/index.test.ts +++ b/2022/day/6/index.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { readFile } from 'node:fs/promises'; import { describe, it } from 'node:test'; +import { getInput } from '../../../utils/file.ts'; import { part1, part2 } from './index.ts'; -const input = await readFile(`${import.meta.dirname}/input`, 'utf-8'); +const input = await getInput(import.meta.dirname); describe('Day 6', () => { describe('Part 1', () => { diff --git a/README.md b/README.md index 1e65e9b..c582b33 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ npm run lint ### Testing -Run tests using [Vitest](https://vitest.dev/) testing framework. +Run tests using [Node Test runner](https://nodejs.org/api/test.html). ```sh npm test diff --git a/utils/file.ts b/utils/file.ts index 1c240a3..7e3c9ef 100644 --- a/utils/file.ts +++ b/utils/file.ts @@ -1,8 +1,12 @@ import { readFile } from 'node:fs/promises'; import { ENCODING } from './string.ts'; -function getInput(directory: string): Promise { - return readFile(`${directory}/input`, ENCODING); +function getInput(directory: string, filename = 'input'): Promise { + return readFile(`${directory}/${filename}`, ENCODING); } -export { getInput }; +function getInputSample(directory: string, filename = 'input'): Promise { + return getInput(directory, `${filename}.sample`); +} + +export { getInput, getInputSample }; diff --git a/vite.config.ts b/vite.config.ts deleted file mode 100644 index baac3db..0000000 --- a/vite.config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { defineConfig } from 'vitest/config'; - -export default defineConfig({ - test: { - // ... - }, -});