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

nguyenhuuit / adventofcode-runner / #6

11 Jun 2025 07:02AM UTC coverage: 12.757% (+3.3%) from 9.492%
#6

push

nguyenhuuit
feat: integrate telemetry

26 of 167 branches covered (15.57%)

Branch coverage included in aggregate %.

15 of 85 new or added lines in 8 files covered. (17.65%)

5 existing lines in 4 files now uncovered.

61 of 515 relevant lines covered (11.84%)

0.24 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

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

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

24
  const executeSolution = useExecuteAsStream(executionStore);
×
25

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

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

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

83
  return { name, size };
×
84
};
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