-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
319 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,180 +1,150 @@ | ||
const prettier = require("prettier"); | ||
const { diff } = require("jest-diff"); | ||
const prettier = require('prettier') | ||
const { diff } = require('jest-diff') | ||
|
||
function format(input) { | ||
return prettier.format(input, { | ||
parser: "css", | ||
parser: 'css', | ||
printWidth: 100, | ||
}); | ||
}) | ||
} | ||
|
||
expect.extend({ | ||
// Compare two CSS strings with all whitespace removed | ||
// This is probably naive but it's fast and works well enough. | ||
toMatchCss(received, argument) { | ||
function stripped(str) { | ||
return str.replace(/\s/g, "").replace(/;/g, ""); | ||
return str.replace(/\s/g, '').replace(/;/g, '') | ||
} | ||
|
||
const options = { | ||
comment: "stripped(received) === stripped(argument)", | ||
comment: 'stripped(received) === stripped(argument)', | ||
isNot: this.isNot, | ||
promise: this.promise, | ||
}; | ||
} | ||
|
||
const pass = stripped(received) === stripped(argument); | ||
const pass = stripped(received) === stripped(argument) | ||
|
||
const message = pass | ||
? () => { | ||
return ( | ||
this.utils.matcherHint( | ||
"toMatchCss", | ||
undefined, | ||
undefined, | ||
options | ||
) + | ||
"\n\n" + | ||
this.utils.matcherHint('toMatchCss', undefined, undefined, options) + | ||
'\n\n' + | ||
`Expected: not ${this.utils.printExpected(format(received))}\n` + | ||
`Received: ${this.utils.printReceived(format(argument))}` | ||
); | ||
) | ||
} | ||
: () => { | ||
const actual = format(received); | ||
const expected = format(argument); | ||
const actual = format(received) | ||
const expected = format(argument) | ||
|
||
const diffString = diff(expected, actual, { | ||
expand: this.expand, | ||
}); | ||
}) | ||
|
||
return ( | ||
this.utils.matcherHint( | ||
"toMatchCss", | ||
undefined, | ||
undefined, | ||
options | ||
) + | ||
"\n\n" + | ||
(diffString && diffString.includes("- Expect") | ||
this.utils.matcherHint('toMatchCss', undefined, undefined, options) + | ||
'\n\n' + | ||
(diffString && diffString.includes('- Expect') | ||
? `Difference:\n\n${diffString}` | ||
: `Expected: ${this.utils.printExpected(expected)}\n` + | ||
`Received: ${this.utils.printReceived(actual)}`) | ||
); | ||
}; | ||
) | ||
} | ||
|
||
return { actual: received, message, pass }; | ||
return { actual: received, message, pass } | ||
}, | ||
toIncludeCss(received, argument) { | ||
function stripped(str) { | ||
return str.replace(/\s/g, "").replace(/;/g, ""); | ||
return str.replace(/\s/g, '').replace(/;/g, '') | ||
} | ||
|
||
const options = { | ||
comment: "stripped(received).includes(stripped(argument))", | ||
comment: 'stripped(received).includes(stripped(argument))', | ||
isNot: this.isNot, | ||
promise: this.promise, | ||
}; | ||
} | ||
|
||
const pass = stripped(received).includes(stripped(argument)); | ||
const pass = stripped(received).includes(stripped(argument)) | ||
|
||
const message = pass | ||
? () => { | ||
return ( | ||
this.utils.matcherHint( | ||
"toIncludeCss", | ||
undefined, | ||
undefined, | ||
options | ||
) + | ||
"\n\n" + | ||
this.utils.matcherHint('toIncludeCss', undefined, undefined, options) + | ||
'\n\n' + | ||
`Expected: not ${this.utils.printExpected(format(received))}\n` + | ||
`Received: ${this.utils.printReceived(format(argument))}` | ||
); | ||
) | ||
} | ||
: () => { | ||
const actual = format(received); | ||
const expected = format(argument); | ||
const actual = format(received) | ||
const expected = format(argument) | ||
|
||
const diffString = diff(expected, actual, { | ||
expand: this.expand, | ||
}); | ||
}) | ||
|
||
return ( | ||
this.utils.matcherHint( | ||
"toIncludeCss", | ||
undefined, | ||
undefined, | ||
options | ||
) + | ||
"\n\n" + | ||
(diffString && diffString.includes("- Expect") | ||
this.utils.matcherHint('toIncludeCss', undefined, undefined, options) + | ||
'\n\n' + | ||
(diffString && diffString.includes('- Expect') | ||
? `Difference:\n\n${diffString}` | ||
: `Expected: ${this.utils.printExpected(expected)}\n` + | ||
`Received: ${this.utils.printReceived(actual)}`) | ||
); | ||
}; | ||
) | ||
} | ||
|
||
return { actual: received, message, pass }; | ||
return { actual: received, message, pass } | ||
}, | ||
}); | ||
}) | ||
|
||
expect.extend({ | ||
// Compare two CSS strings with all whitespace removed | ||
// This is probably naive but it's fast and works well enough. | ||
toMatchFormattedCss(received, argument) { | ||
function format(input) { | ||
return prettier.format(input.replace(/\n/g, ""), { | ||
parser: "css", | ||
return prettier.format(input.replace(/\n/g, ''), { | ||
parser: 'css', | ||
printWidth: 100, | ||
}); | ||
}) | ||
} | ||
const options = { | ||
comment: "stripped(received) === stripped(argument)", | ||
comment: 'stripped(received) === stripped(argument)', | ||
isNot: this.isNot, | ||
promise: this.promise, | ||
}; | ||
} | ||
|
||
let formattedReceived = format(received); | ||
let formattedArgument = format(argument); | ||
let formattedReceived = format(received) | ||
let formattedArgument = format(argument) | ||
|
||
const pass = formattedReceived === formattedArgument; | ||
const pass = formattedReceived === formattedArgument | ||
|
||
const message = pass | ||
? () => { | ||
return ( | ||
this.utils.matcherHint( | ||
"toMatchCss", | ||
undefined, | ||
undefined, | ||
options | ||
) + | ||
"\n\n" + | ||
this.utils.matcherHint('toMatchCss', undefined, undefined, options) + | ||
'\n\n' + | ||
`Expected: not ${this.utils.printExpected(formattedReceived)}\n` + | ||
`Received: ${this.utils.printReceived(formattedArgument)}` | ||
); | ||
) | ||
} | ||
: () => { | ||
const actual = formattedReceived; | ||
const expected = formattedArgument; | ||
const actual = formattedReceived | ||
const expected = formattedArgument | ||
|
||
const diffString = diff(expected, actual, { | ||
expand: this.expand, | ||
}); | ||
}) | ||
|
||
return ( | ||
this.utils.matcherHint( | ||
"toMatchCss", | ||
undefined, | ||
undefined, | ||
options | ||
) + | ||
"\n\n" + | ||
(diffString && diffString.includes("- Expect") | ||
this.utils.matcherHint('toMatchCss', undefined, undefined, options) + | ||
'\n\n' + | ||
(diffString && diffString.includes('- Expect') | ||
? `Difference:\n\n${diffString}` | ||
: `Expected: ${this.utils.printExpected(expected)}\n` + | ||
`Received: ${this.utils.printReceived(actual)}`) | ||
); | ||
}; | ||
) | ||
} | ||
|
||
return { actual: received, message, pass }; | ||
return { actual: received, message, pass } | ||
}, | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
const _ = require("lodash"); | ||
const extractGridAreaNames = require("./util/extractGridAreaNames"); | ||
const _ = require('lodash') | ||
const extractGridAreaNames = require('./util/extractGridAreaNames') | ||
|
||
module.exports = function ({ addUtilities, matchUtilities, theme, variants }) { | ||
const gridAreaNames = extractGridAreaNames(theme("gridTemplateAreas")); | ||
const gridAreaNames = extractGridAreaNames(theme('gridTemplateAreas')) | ||
|
||
const templateAreas = _.reduce( | ||
theme("gridTemplateAreas"), | ||
theme('gridTemplateAreas'), | ||
(templates, area, name) => { | ||
return { | ||
...templates, | ||
[`.grid-areas-${name}`]: { | ||
"grid-template-areas": area | ||
'grid-template-areas': area | ||
.map((row) => { | ||
return `"${row}"`; | ||
return `"${row}"` | ||
}) | ||
.join("\n"), | ||
.join('\n'), | ||
}, | ||
}; | ||
} | ||
}, | ||
{} | ||
); | ||
) | ||
|
||
addUtilities([templateAreas], variants("gridTemplateAreas")); | ||
addUtilities([templateAreas], variants('gridTemplateAreas')) | ||
|
||
const namedAreas = gridAreaNames.reduce((areas, name) => { | ||
return { | ||
...areas, | ||
[`.grid-in-${name}`]: { | ||
"grid-area": name, | ||
'grid-area': name, | ||
}, | ||
}; | ||
}, {}); | ||
} | ||
}, {}) | ||
|
||
addUtilities([namedAreas], []); | ||
addUtilities([namedAreas], []) | ||
|
||
const namedLines = gridAreaNames.reduce((lines, name) => { | ||
return { | ||
...lines, | ||
[`.row-start-${name}`]: { | ||
"grid-row-start": `${name}-start`, | ||
'grid-row-start': `${name}-start`, | ||
}, | ||
[`.row-end-${name}`]: { | ||
"grid-row-end": `${name}-end`, | ||
'grid-row-end': `${name}-end`, | ||
}, | ||
[`.col-start-${name}`]: { | ||
"grid-column-start": `${name}-start`, | ||
'grid-column-start': `${name}-start`, | ||
}, | ||
[`.col-end-${name}`]: { | ||
"grid-column-end": `${name}-end`, | ||
'grid-column-end': `${name}-end`, | ||
}, | ||
}; | ||
}, {}); | ||
} | ||
}, {}) | ||
|
||
addUtilities([namedLines], []); | ||
addUtilities([namedLines], []) | ||
|
||
// allow arbitrary values | ||
matchUtilities({ | ||
"grid-areas": (value) => { | ||
value = `"${value}"`; | ||
value = value.replace(/ *, */g, '" "'); | ||
'grid-areas': (value) => { | ||
value = `"${value}"` | ||
value = value.replace(/ *, */g, '" "') | ||
return { | ||
"grid-template-areas": `${value}`, | ||
}; | ||
'grid-template-areas': `${value}`, | ||
} | ||
}, | ||
"grid-in": (value) => { | ||
'grid-in': (value) => { | ||
return { | ||
"grid-area": `${value}`, | ||
}; | ||
'grid-area': `${value}`, | ||
} | ||
}, | ||
}); | ||
}; | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
const _ = require("lodash"); | ||
const _ = require('lodash') | ||
|
||
module.exports = function (gridTemplateAreas) { | ||
return _.uniq( | ||
_.flatMap(gridTemplateAreas, (row) => { | ||
return _.flatMap(row, (area) => { | ||
// extract grid area names from the gridTemplate | ||
return _.flatMap(area.match(/[^\s]+/g), (match) => { | ||
if (match !== ".") { | ||
return match; | ||
if (match !== '.') { | ||
return match | ||
} | ||
return []; | ||
}); | ||
}); | ||
return [] | ||
}) | ||
}) | ||
}) | ||
); | ||
}; | ||
) | ||
} |
Oops, something went wrong.