Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:fix": "yarn lint -- --fix",
"precommit": "lint-staged",
"prepublish": "yarn build",
"prettier": "prettier 'src/**/*.js' --write --single-quote=true --print-width=120",
"prettier": "prettier 'src/**/*.js' --write --single-quote=true --print-width=120 --no-config",
"test": "jest",
"test:coverage": "yarn test -- --coverage",
"test:report": "codecov",
Expand Down
30 changes: 15 additions & 15 deletions src/scope/templates/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,57 @@
exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 0 1`] = `
"
if (typeof window !== 'undefined') {
console.groupCollapsed(title);
console.groupCollapsed(TITLE);
} else {
console.log('▼ ', title);
console.log('▼ ', TITLE);
}
"
`;

exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 1 1`] = `
"
if (typeof window !== 'undefined') {
console.groupCollapsed(title);
console.groupCollapsed(TITLE);
} else {
console.log('| ▼ ', title);
console.log('| ▼ ', TITLE);
}
"
`;

exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 2 1`] = `
"
if (typeof window !== 'undefined') {
console.groupCollapsed(title);
console.groupCollapsed(TITLE);
} else {
console.log('| | ▼ ', title);
console.log('| | ▼ ', TITLE);
}
"
`;

exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 3 1`] = `
"
if (typeof window !== 'undefined') {
console.groupCollapsed(title);
console.groupCollapsed(TITLE);
} else {
console.log('| | | ▼ ', title);
console.log('| | | ▼ ', TITLE);
}
"
`;

exports[`Templates .buildGroupEnd calls template with correct string 1`] = `
"
if (typeof window !== 'undefined') {
console.groupEnd(title);
console.groupEnd(TITLE);
}
"
`;

exports[`Templates .buildLog calls template with correct string and indentation level: 1 1`] = `
"
if (typeof window !== 'undefined') {
console.log(args);
console.log(ARGS);
} else {
console.log('| | ', args);
console.log('| | ', ARGS);

}
"
Expand All @@ -62,9 +62,9 @@ exports[`Templates .buildLog calls template with correct string and indentation
exports[`Templates .buildLog calls template with correct string and indentation level: 2 1`] = `
"
if (typeof window !== 'undefined') {
console.log(args);
console.log(ARGS);
} else {
console.log('| | | ', args);
console.log('| | | ', ARGS);

}
"
Expand All @@ -73,9 +73,9 @@ exports[`Templates .buildLog calls template with correct string and indentation
exports[`Templates .buildLog calls template with correct string and indentation level: 3 1`] = `
"
if (typeof window !== 'undefined') {
console.log(args);
console.log(ARGS);
} else {
console.log('| | | | ', args);
console.log('| | | | ', ARGS);

}
"
Expand Down
24 changes: 12 additions & 12 deletions src/scope/templates/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const buildGroupCollapsed = template => title => level => {
const buildGroupCollapsed = template => TITLE => level => {
const indentation = indentWith(level, '| ', '▼ ');

return template(`
if (typeof window !== 'undefined') {
console.groupCollapsed(title);
console.groupCollapsed(TITLE);
} else {
console.log('${indentation}', title);
console.log('${indentation}', TITLE);
}
`)({ title });
`)({ TITLE });
};

const buildGroupEnd = template => title =>
const buildGroupEnd = template => TITLE =>
template(`
if (typeof window !== 'undefined') {
console.groupEnd(title);
console.groupEnd(TITLE);
}
`)({ title });
`)({ TITLE });

const buildLog = template => (...args) => level => {
const buildLog = template => (...ARGS) => level => {
if (level == 0) {
return template('console.log(args);')({ args });
return template('console.log(ARGS);')({ ARGS });
}

const indentation = indentWith(level, '| ', '| ');
return template(`
if (typeof window !== 'undefined') {
console.log(args);
console.log(ARGS);
} else {
console.log('${indentation}', args);
console.log('${indentation}', ARGS);

}
`)({ args });
`)({ ARGS });
};

const indentWith = (level, str, initial) => Array.from({ length: level }).reduce(acc => `${str}${acc}`, initial);
Expand Down
8 changes: 4 additions & 4 deletions src/scope/templates/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Templates', () => {
const templateCurry = jest.fn();
const { buildGroupCollapsed } = templateHelpers(template);
buildGroupCollapsed('matt')(0);
expect(templateCurry).toHaveBeenCalledWith({ title: 'matt' });
expect(templateCurry).toHaveBeenCalledWith({ TITLE: 'matt' });
});

it('returns value from invoking template', () => {
Expand All @@ -41,7 +41,7 @@ describe('Templates', () => {
const templateCurry = jest.fn();
const { buildGroupEnd } = templateHelpers(template);
buildGroupEnd('matt');
expect(templateCurry).toHaveBeenCalledWith({ title: 'matt' });
expect(templateCurry).toHaveBeenCalledWith({ TITLE: 'matt' });
});

it('returns value from invoking template', () => {
Expand All @@ -56,7 +56,7 @@ describe('Templates', () => {
const template = jest.fn(() => noop);
const { buildLog } = templateHelpers(template);
buildLog('bob', 'woz', 'ere')(0);
expect(template).toHaveBeenCalledWith('console.log(args);');
expect(template).toHaveBeenCalledWith('console.log(ARGS);');
});

each([[1], [2], [3]]).it('calls template with correct string and indentation level: %d', level => {
Expand All @@ -71,7 +71,7 @@ describe('Templates', () => {
const templateCurry = jest.fn();
const { buildLog } = templateHelpers(template);
buildLog('matt', 'woz', 'ere')(0);
expect(templateCurry).toHaveBeenCalledWith({ args: ['matt', 'woz', 'ere'] });
expect(templateCurry).toHaveBeenCalledWith({ ARGS: ['matt', 'woz', 'ere'] });
});

it('returns value from invoking template', () => {
Expand Down