Skip to content

Commit 79bafcc

Browse files
committed
Testing and docs
1 parent 25323b9 commit 79bafcc

File tree

5 files changed

+329
-12
lines changed

5 files changed

+329
-12
lines changed

.jest.config.mjs

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
export default {
7+
// All imported modules in your tests should be mocked automatically
8+
// automock: false,
9+
10+
// Stop running tests after `n` failures
11+
// bail: 0,
12+
13+
// The directory where Jest should store its cached dependency information
14+
// cacheDirectory: "/home/mayfield/tmp/jest_rs",
15+
16+
// Automatically clear mock calls and instances between every test
17+
clearMocks: true,
18+
19+
// Indicates whether the coverage information should be collected while executing the test
20+
// collectCoverage: false,
21+
22+
// An array of glob patterns indicating a set of files for which coverage information should be collected
23+
// collectCoverageFrom: undefined,
24+
25+
// The directory where Jest should output its coverage files
26+
// coverageDirectory: undefined,
27+
28+
// An array of regexp pattern strings used to skip coverage collection
29+
// coveragePathIgnorePatterns: [
30+
// "/node_modules/"
31+
// ],
32+
33+
// Indicates which provider should be used to instrument code for coverage
34+
coverageProvider: "v8",
35+
36+
// A list of reporter names that Jest uses when writing coverage reports
37+
// coverageReporters: [
38+
// "json",
39+
// "text",
40+
// "lcov",
41+
// "clover"
42+
// ],
43+
44+
// An object that configures minimum threshold enforcement for coverage results
45+
// coverageThreshold: undefined,
46+
47+
// A path to a custom dependency extractor
48+
// dependencyExtractor: undefined,
49+
50+
// Make calling deprecated APIs throw helpful error messages
51+
// errorOnDeprecated: false,
52+
53+
// Force coverage collection from ignored files using an array of glob patterns
54+
// forceCoverageMatch: [],
55+
56+
// A path to a module which exports an async function that is triggered once before all test suites
57+
// globalSetup: undefined,
58+
59+
// A path to a module which exports an async function that is triggered once after all test suites
60+
// globalTeardown: undefined,
61+
62+
// A set of global variables that need to be available in all test environments
63+
// globals: {},
64+
65+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66+
// maxWorkers: "50%",
67+
68+
// An array of directory names to be searched recursively up from the requiring module's location
69+
// moduleDirectories: [
70+
// "node_modules"
71+
// ],
72+
73+
// An array of file extensions your modules use
74+
// moduleFileExtensions: [
75+
// "js",
76+
// "json",
77+
// "jsx",
78+
// "ts",
79+
// "tsx",
80+
// "node"
81+
// ],
82+
83+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84+
// moduleNameMapper: {},
85+
86+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87+
// modulePathIgnorePatterns: [],
88+
89+
// Activates notifications for test results
90+
// notify: false,
91+
92+
// An enum that specifies notification mode. Requires { notify: true }
93+
// notifyMode: "failure-change",
94+
95+
// A preset that is used as a base for Jest's configuration
96+
// preset: undefined,
97+
98+
// Run tests from one or more projects
99+
// projects: undefined,
100+
101+
// Use this configuration option to add custom reporters to Jest
102+
// reporters: undefined,
103+
104+
// Automatically reset mock state between every test
105+
// resetMocks: false,
106+
107+
// Reset the module registry before running each individual test
108+
// resetModules: false,
109+
110+
// A path to a custom resolver
111+
// resolver: undefined,
112+
113+
// Automatically restore mock state between every test
114+
// restoreMocks: false,
115+
116+
// The root directory that Jest should scan for tests and modules within
117+
// rootDir: undefined,
118+
119+
// A list of paths to directories that Jest should use to search for files in
120+
// roots: [
121+
// "<rootDir>"
122+
// ],
123+
124+
// Allows you to use a custom runner instead of Jest's default test runner
125+
// runner: "jest-runner",
126+
127+
// The paths to modules that run some code to configure or set up the testing environment before each test
128+
// setupFiles: [],
129+
130+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
131+
// setupFilesAfterEnv: [],
132+
133+
// The number of seconds after which a test is considered as slow and reported as such in the results.
134+
// slowTestThreshold: 5,
135+
136+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
137+
// snapshotSerializers: [],
138+
139+
// The test environment that will be used for testing
140+
testEnvironment: "node",
141+
142+
// Options that will be passed to the testEnvironment
143+
// testEnvironmentOptions: {},
144+
145+
// Adds a location field to test results
146+
// testLocationInResults: false,
147+
148+
// The glob patterns Jest uses to detect test files
149+
// testMatch: [
150+
// "**/__tests__/**/*.[jt]s?(x)",
151+
// "**/?(*.)+(spec|test).[tj]s?(x)"
152+
// ],
153+
154+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
155+
// testPathIgnorePatterns: [
156+
// "/node_modules/"
157+
// ],
158+
159+
// The regexp pattern or array of patterns that Jest uses to detect test files
160+
// testRegex: [],
161+
162+
// This option allows the use of a custom results processor
163+
// testResultsProcessor: undefined,
164+
165+
// This option allows use of a custom test runner
166+
// testRunner: "jasmine2",
167+
168+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169+
// testURL: "http://localhost",
170+
171+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172+
// timers: "real",
173+
174+
// A map from regular expressions to paths to transformers
175+
// transform: undefined,
176+
177+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178+
// transformIgnorePatterns: [
179+
// "/node_modules/",
180+
// "\\.pnp\\.[^\\/]+$"
181+
// ],
182+
183+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184+
// unmockedModulePathPatterns: undefined,
185+
186+
// Indicates whether each individual test should be reported during the run
187+
// verbose: undefined,
188+
189+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190+
// watchPathIgnorePatterns: [],
191+
192+
// Whether to use watchman for file crawling
193+
// watchman: true,
194+
};

README

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
jsfit
22
========
3-
JavaScript FIT file encoder (and unmaintained decoder)
3+
JavaScript FIT file encoder and decoder
44

55
Create Garmin .FIT files for your sports activities in pure JS.
66

@@ -17,21 +17,21 @@ Usage
1717
```js
1818
import * as fit from './path/to/fit.mjs';
1919

20-
const fit = new jsfit.FitParser();
21-
fit.addMessage('file_id', {
20+
const fitParser = new fit.FitParser();
21+
fitParser.addMessage('file_id', {
2222
manufacturer: 'strava',
2323
type: 'segment',
2424
time_created: new Date()
2525
});
26-
fit.addMessage('segment_id', {
26+
fitParser.addMessage('segment_id', {
2727
name: 'testing live segment',
2828
enabled: true,
2929
sport: 'cycling',
3030
selection_type: 'starred',
3131
uuid: 'foobar',
3232
default_race_leader: 1,
3333
});
34-
fit.addMessage('segment_lap', {
34+
fitParser.addMessage('segment_lap', {
3535
uuid: 'foobar',
3636
total_distance: 625,
3737
start_position_lat: 43.67,
@@ -47,7 +47,7 @@ fit.addMessage('segment_lap', {
4747
value: 0
4848
}
4949
});
50-
fit.addMessage('segment_leaderboard_entry', {
50+
fitParser.addMessage('segment_leaderboard_entry', {
5151
activity_id_string: 'randomid',
5252
segment_time: 2023.0,
5353
type: 'rival',
@@ -57,7 +57,7 @@ fit.addMessage('segment_leaderboard_entry', {
5757
value: 0
5858
}
5959
});
60-
fit.addMessage('segment_point', {
60+
fitParser.addMessage('segment_point', {
6161
altitude: 1098.8,
6262
distance: 0.0,
6363
position_lat: 43.6766,
@@ -68,7 +68,7 @@ fit.addMessage('segment_point', {
6868
value: 0
6969
}
7070
});
71-
fit.addMessage('segment_point', {
71+
fitParser.addMessage('segment_point', {
7272
altitude: 1198.8,
7373
distance: 1.0,
7474
position_lat: 44.6766,
@@ -79,6 +79,6 @@ fit.addMessage('segment_point', {
7979
value: 1
8080
}
8181
});
82-
const buf = fit.encode();
83-
// buf is a Uint8Array that you can Blob()ify and download.
82+
const u8Arr = fitParser.encode();
83+
console.info("Here it is:", u8Arr);
8484
```

example.mjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Run me from the src dir like `node ./exmaple.mjs`
2+
import * as fit from './src/fit.mjs';
3+
4+
const fitParser = new fit.FitParser();
5+
fitParser.addMessage('file_id', {
6+
manufacturer: 'strava',
7+
type: 'segment',
8+
time_created: new Date()
9+
});
10+
fitParser.addMessage('segment_id', {
11+
name: 'testing live segment',
12+
enabled: true,
13+
sport: 'cycling',
14+
selection_type: 'starred',
15+
uuid: 'foobar',
16+
default_race_leader: 1,
17+
});
18+
fitParser.addMessage('segment_lap', {
19+
uuid: 'foobar',
20+
total_distance: 625,
21+
start_position_lat: 43.67,
22+
start_position_long: -116.16,
23+
swc_lat: 43.67,
24+
swc_long: -116.16,
25+
nec_lat: 43.7048,
26+
nec_long: -116.105,
27+
end_position_lat: 43.7,
28+
end_position_long: -116.10,
29+
message_index: {
30+
flags: [],
31+
value: 0
32+
}
33+
});
34+
fitParser.addMessage('segment_leaderboard_entry', {
35+
activity_id_string: 'randomid',
36+
segment_time: 2023.0,
37+
type: 'rival',
38+
name: 'The man from town',
39+
message_index: {
40+
flags: [],
41+
value: 0
42+
}
43+
});
44+
fitParser.addMessage('segment_point', {
45+
altitude: 1098.8,
46+
distance: 0.0,
47+
position_lat: 43.6766,
48+
position_long: -116.16099,
49+
leader_time: [0.0],
50+
message_index: {
51+
flags: [],
52+
value: 0
53+
}
54+
});
55+
fitParser.addMessage('segment_point', {
56+
altitude: 1198.8,
57+
distance: 1.0,
58+
position_lat: 44.6766,
59+
position_long: -117.16099,
60+
leader_time: [2.0],
61+
message_index: {
62+
flags: [],
63+
value: 1
64+
}
65+
});
66+
const u8Arr = fitParser.encode();
67+
console.log("Here it is:", u8Arr);

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
22
"name": "jsfit",
33
"version": "6.9.0",
4-
"description": "JavaScript FIT file encoder (decoder is unmaintained)",
4+
"description": "JavaScript FIT file encoder and decoder",
55
"main": "src/fit.mjs",
6+
"type": "module",
7+
"scripts": {
8+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config .jest.config.mjs",
9+
"test-debug": "node --inspect-brk --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --config .jest.config.mjs"
10+
},
611
"repository": {
712
"type": "git",
813
"url": "git+https://github.com/mayfield/jsfit.git"
@@ -14,6 +19,7 @@
1419
},
1520
"homepage": "https://github.com/mayfield/jsfit#readme",
1621
"devDependencies": {
17-
"eslint": "8.10.0"
22+
"eslint": "8.10.0",
23+
"jest": "27.5.1"
1824
}
1925
}

0 commit comments

Comments
 (0)