Skip to content

Commit

Permalink
fix: quotes should be single
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev committed Oct 7, 2019
1 parent c80e915 commit ae9aa44
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 91 deletions.
2 changes: 1 addition & 1 deletion core/commons-api/test/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getUnauthorized,
getForbidden,
getServiceUnavailable,
getCode,
getCode
} from '../src/index';

describe('testing errors', () => {
Expand Down
62 changes: 31 additions & 31 deletions core/file-locking/src/__tests__/lock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import fs from "fs";
import path from 'path';
import fs from 'fs';

import { lockFile, unlockFile, readFile } from "../index";
import { lockFile, unlockFile, readFile } from '../index';

interface Error {
message: string;
Expand All @@ -18,45 +18,45 @@ const removeTempFile = (filename: string): void => {
});
};

describe("testing locking", () => {
test("file should be found to be locked", done => {
lockFile(getFilePath("package.json"), (error: Error) => {
describe('testing locking', () => {
test('file should be found to be locked', done => {
lockFile(getFilePath('package.json'), (error: Error) => {
expect(error).toBeNull();
removeTempFile("package.json.lock");
removeTempFile('package.json.lock');
done();
});
});

test("file should fail to be found to be locked", done => {
lockFile(getFilePath("package.fail.json"), (error: Error) => {
test('file should fail to be found to be locked', done => {
lockFile(getFilePath('package.fail.json'), (error: Error) => {
expect(error.message).toMatch(
/ENOENT: no such file or directory, stat '(.*)package.fail.json'/
);
done();
});
});

test("file should to be found to be unLock", done => {
unlockFile(getFilePath("package.json.lock"), (error: Error) => {
test('file should to be found to be unLock', done => {
unlockFile(getFilePath('package.json.lock'), (error: Error) => {
expect(error).toBeNull();
done();
});
});

test("read file with no options should to be found to be read it as string", done => {
readFile(getFilePath("package.json"), (error: Error, data: any) => {
test('read file with no options should to be found to be read it as string', done => {
readFile(getFilePath('package.json'), (error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
done();
});
});

test("read file with no options should to be found to be read it as object", done => {
test('read file with no options should to be found to be read it as object', done => {
const options = {
parse: true
};
readFile(
getFilePath("package.json"),
getFilePath('package.json'),
options,
(error: Error, data: any) => {
expect(error).toBeNull();
Expand All @@ -66,61 +66,61 @@ describe("testing locking", () => {
);
});

test("read file with options (parse) should to be not found to be read it", done => {
test('read file with options (parse) should to be not found to be read it', done => {
const options = {
parse: true
};
readFile(getFilePath("package.fail.json"), options, (error: Error) => {
readFile(getFilePath('package.fail.json'), options, (error: Error) => {
expect(error.message).toMatch(
/ENOENT: no such file or directory, open '(.*)package.fail.json'/
);
done();
});
});

test("read file with options should to be found to be read it and fails to be parsed", done => {
test('read file with options should to be found to be read it and fails to be parsed', done => {
const options = {
parse: true
};
const errorMessage =
process.platform === "win32"
? "Unexpected token } in JSON at position 47"
: "Unexpected token } in JSON at position 44";
readFile(getFilePath("wrong.package.json"), options, (error: Error) => {
process.platform === 'win32'
? 'Unexpected token } in JSON at position 47'
: 'Unexpected token } in JSON at position 44';
readFile(getFilePath('wrong.package.json'), options, (error: Error) => {
expect(error.message).toEqual(errorMessage);
done();
});
});

test("read file with options (parse, lock) should to be found to be read it as object", done => {
test('read file with options (parse, lock) should to be found to be read it as object', done => {
const options = {
parse: true,
lock: true
};
readFile(
getFilePath("package2.json"),
getFilePath('package2.json'),
options,
(error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
removeTempFile("package2.json.lock");
removeTempFile('package2.json.lock');
done();
}
);
});

test("read file with options (parse, lock) should to be found to be read it and fails to be parsed", done => {
test('read file with options (parse, lock) should to be found to be read it and fails to be parsed', done => {
const options = {
parse: true,
lock: true
};
const errorMessage =
process.platform === "win32"
? "Unexpected token } in JSON at position 47"
: "Unexpected token } in JSON at position 44";
readFile(getFilePath("wrong.package.json"), options, (error: Error) => {
process.platform === 'win32'
? 'Unexpected token } in JSON at position 47'
: 'Unexpected token } in JSON at position 44';
readFile(getFilePath('wrong.package.json'), options, (error: Error) => {
expect(error.message).toEqual(errorMessage);
removeTempFile("wrong.package.json.lock");
removeTempFile('wrong.package.json.lock');
done();
});
});
Expand Down
12 changes: 6 additions & 6 deletions core/file-locking/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import locker from "lockfile";
import fs from "fs";
import path from "path";
import locker from 'lockfile';
import fs from 'fs';
import path from 'path';

import { Callback } from "@verdaccio/types";
import { Callback } from '@verdaccio/types';

// locks a file by creating a lock file
const lockFile = function(name: string, callback: Callback): void {
Expand Down Expand Up @@ -98,7 +98,7 @@ function readFile(
options: any = {},
callback: any = (): void => {}
): void {
if (typeof options === "function") {
if (typeof options === 'function') {
callback = options;
options = {};
}
Expand All @@ -123,7 +123,7 @@ function readFile(

const read = function(): Promise<any> {
return new Promise<any>((resolve, reject): void => {
fs.readFile(name, "utf8", function(err, contents) {
fs.readFile(name, 'utf8', function(err, contents) {
if (err) {
return reject(err);
}
Expand Down
Loading

0 comments on commit ae9aa44

Please sign in to comment.