• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nguyenhuuit / adventofcode-runner / #8

12 Jun 2025 02:29PM UTC coverage: 23.395% (+10.8%) from 12.572%
#8

push

nguyenhuuit
fix: newline was removed in sample

48 of 167 branches covered (28.74%)

Branch coverage included in aggregate %.

6 of 7 new or added lines in 2 files covered. (85.71%)

116 of 534 relevant lines covered (21.72%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/hooks/useInputFile.ts
1
import fs from 'fs';
2
import { useStore } from 'zustand';
3

4
import { useCallback, useEffect, useState } from 'react';
5

6
import { TrackingEvent } from '@utils/analytics';
7
import { aocClient } from '@utils/aocClient';
8
import { InputMode, VALID_YEARS } from '@utils/constants';
9
import { logger } from '@utils/logger';
10
import { extractSampleInput } from '@utils/misc';
11

12
import { useExecuteAsStream } from '@hooks/useExecuteAsStream';
13
import { ExecutionStoreInstance } from '@hooks/useExecutionStore';
14
import { useTelemetry } from '@hooks/useTelemetry';
15
import { useWatcher } from '@hooks/useWatcher';
16

17
export const useInputFile = (executionStore: ExecutionStoreInstance): AppFile => {
×
18
  const [name, setName] = useState<string>('');
×
19
  const [size, setSize] = useState<number>(0);
×
20
  const { year, day, inputMode, getRelativeDir, getInputFile } = useStore(executionStore);
×
21
  const relativeDir = getRelativeDir();
×
22
  const inputFileName = getInputFile();
×
23
  const { track } = useTelemetry(executionStore);
×
24

25
  const executeSolution = useExecuteAsStream(executionStore);
×
26

27
  const handleFileChange = useCallback(() => {
×
28
    executeSolution();
×
29
  }, [executeSolution]);
30

31
  useWatcher({ filePath: name, onChange: handleFileChange });
×
32

33
  useEffect(() => {
×
34
    if (!fs.existsSync(relativeDir)) {
×
35
      fs.mkdirSync(relativeDir, { recursive: true });
×
36
    }
37
    if (!fs.existsSync(inputFileName)) {
×
38
      let data = '';
×
39
      fs.writeFileSync(inputFileName, data, { flag: 'as+' });
×
40
    }
41
    const stats = fs.statSync(inputFileName);
×
42
    setName(inputFileName);
×
43
    setSize(stats.size);
×
44
    if (!VALID_YEARS.includes(year)) {
×
45
      return;
×
46
    }
47
    if (stats.size === 0 && inputMode === InputMode.INPUT) {
×
48
      aocClient
×
49
        .fetchInput(year, day)
50
        .then((data) => {
51
          if (data) {
×
52
            fs.writeFileSync(inputFileName, data);
×
53
            const stats = fs.statSync(inputFileName);
×
54
            setSize(stats.size);
×
55
            track(TrackingEvent.INPUT_FETCH, { success: true });
×
56
          }
57
        })
58
        .catch((error) => {
59
          track(TrackingEvent.INPUT_FETCH, { success: false });
×
60
          logger.error(`Failed to fetch input: ${error}`);
×
61
        });
62
    }
63
    if (stats.size === 0 && inputMode === InputMode.SAMPLE) {
×
64
      aocClient
×
65
        .fetchProblem(year, day)
66
        .then((html) => {
67
          if (html) {
×
NEW
68
            const sampleInput = extractSampleInput(html);
×
69
            if (sampleInput) {
×
70
              fs.writeFileSync(inputFileName, sampleInput);
×
71
              const stats = fs.statSync(inputFileName);
×
72
              setSize(stats.size);
×
73
              track(TrackingEvent.SAMPLE_FETCH, { success: true });
×
74
            }
75
          }
76
        })
77
        .catch((error) => {
78
          track(TrackingEvent.SAMPLE_FETCH, { success: true });
×
79
          logger.error(`Failed to fetch problem: ${error}`);
×
80
        });
81
    }
82
  }, [relativeDir, inputFileName, year, day, inputMode, track]);
83

84
  return { name, size };
×
85
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc