Skip to content

Commit

Permalink
feat(#50): filter undefined, empty
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Sep 26, 2024
1 parent 0789305 commit e6f6926
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const fs = require('fs');
function tokens(file) {
try {
const content = fs.readFileSync(file, 'utf8');
return content.split('\n');
return content.split('\n').filter((c) => c !== undefined && c !== "");

Check failure on line 34 in src/tokens.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 20)

Strings must use singlequote

Check failure on line 34 in src/tokens.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
} catch (error) {
console.error(`Error reading tokens file: ${error.message}`);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions test/resources/one-empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aaa
11 changes: 10 additions & 1 deletion test/tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ describe('Test case for tokens.js', function() {
assert.deepEqual(
fetched,
expected,
`fetched tokens ${fetched} don't match with expected ${expected}`
`parsed tokens ${fetched} don't match with expected ${expected}`
)
});
it("fetches one token with one empty line", function () {

Check failure on line 46 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 20)

Strings must use singlequote

Check failure on line 46 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 20)

Unexpected space before function parentheses

Check failure on line 46 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 46 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build

Unexpected space before function parentheses
const parsed = tokens("test/resources/one-empty.txt");

Check failure on line 47 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 20)

Strings must use singlequote

Check failure on line 47 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
const expected = ["aaa"];

Check failure on line 48 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 20)

Strings must use singlequote

Check failure on line 48 in test/tokens.test.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
assert.deepEqual(
parsed,
expected,
`parsed tokens ${parsed} don't match with expected tokens: ${expected}`
)
});
});

0 comments on commit e6f6926

Please sign in to comment.