Skip to content

Commit

Permalink
fix: support Windows (#26)
Browse files Browse the repository at this point in the history
* fix: support Windows

* test: win line endings <3
  • Loading branch information
P0lip authored Feb 15, 2021
1 parent d045a35 commit 884265a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
16 changes: 15 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
version: 2
version: 2.1

orbs:
windows: circleci/windows@2.2.0

jobs:
test_node_12:
Expand All @@ -8,6 +11,15 @@ jobs:
- checkout
- run: yarn
- run: yarn test.prod

test_windows:
executor:
name: windows/default
steps:
- checkout
- run: yarn
- run: yarn test.prod

release:
docker:
- image: circleci/node:12
Expand All @@ -22,9 +34,11 @@ workflows:
test_and_release:
jobs:
- test_node_12
- test_windows
- release:
filters:
branches:
only: master
requires:
- test_node_12
- test_windows
1 change: 1 addition & 0 deletions src/__tests__/__fixtures__/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
12 changes: 5 additions & 7 deletions src/__tests__/file.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { readFile } from 'fs';
import * as path from 'path';
import * as URI from 'urijs';
import { resolveFile } from '../file';

jest.mock('fs');

describe('resolveFile()', () => {
it('works', async () => {
((readFile as unknown) as jest.Mock).mockImplementation((_, __, cb) => cb(undefined, 'root:*'));
await expect(resolveFile({ path: () => '/etc/passwd' } as URI)).resolves.toEqual('root:*');
const uri = new URI(path.join(__dirname, '__fixtures__/test.json'));
await expect(resolveFile(uri)).resolves.toMatch(/^{\}/);
});

it('handles failures', async () => {
((readFile as unknown) as jest.Mock).mockImplementation((_, __, cb) => cb(new Error('Using shadow, ha, ha')));
await expect(resolveFile({ path: () => '/etc/passwd' } as URI)).rejects.toThrowError('Using shadow, ha, ha');
const uri = new URI(path.join(__dirname, '__fixtures__/baz.json'));
await expect(resolveFile(uri)).rejects.toThrowError();
});
});
9 changes: 6 additions & 3 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import * as URI from 'urijs';

export function resolveFile(ref: URI) {
return new Promise((resolve, reject) => {
const path = ref.path();
const path = ref.href();
readFile(path, 'utf8', (err, data) => {
if (err) reject(err);
resolve(data);
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

0 comments on commit 884265a

Please sign in to comment.