Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Bornö committed Nov 1, 2022
1 parent b111fb0 commit d3d8a06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
14 changes: 14 additions & 0 deletions test/unit/google-font-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
expect(css).toBe('OK\n')
expect(fetch).toHaveBeenCalledTimes(1)
Expand All @@ -112,6 +113,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
expect(css).toBe('1\n2\n3\n4\n5\n6\n')
expect(fetch).toHaveBeenCalledTimes(6)
Expand Down Expand Up @@ -163,6 +165,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Failed to fetch font \`Alkalami\`.
Expand All @@ -180,6 +183,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"@next/font/google has no default export"`
Expand All @@ -196,6 +200,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unknown font \`Unknown Font\`"`
Expand All @@ -212,6 +217,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Unknown weight \`123\` for font \`Inter\`.
Expand All @@ -229,6 +235,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Missing weight for font \`Abel\`.
Expand All @@ -246,6 +253,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Unknown style \`normal\` for font \`Molle\`.
Expand All @@ -263,6 +271,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid display value \`invalid\` for font \`Inter\`.
Expand All @@ -280,6 +289,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Axes can only be defined for variable fonts"`
Expand All @@ -296,6 +306,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Font \`Lora\` has no definable \`axes\`"`
Expand All @@ -312,6 +323,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid axes value for font \`Inter\`, expected an array of axes.
Expand All @@ -329,6 +341,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid axes value \`INVALID\` for font \`Roboto Flex\`.
Expand All @@ -346,6 +359,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unexpected \`variable\` in weight array for font \`Inter\`. You only need \`variable\`, it includes all available weights."`
Expand Down
33 changes: 23 additions & 10 deletions test/unit/local-font-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ describe('@next/font/local', () => {
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
},
})

expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
}
Expand All @@ -33,14 +34,15 @@ describe('@next/font/local', () => {
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
},
})

expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 100 900;
Expand All @@ -66,6 +68,7 @@ describe('@next/font/local', () => {
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
},
Expand All @@ -75,7 +78,7 @@ describe('@next/font/local', () => {
"@font-face {
font-feature-settings: \\"smcp\\" on;
ascent-override: 90%;
font-family: 'my-font';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
}
Expand Down Expand Up @@ -115,38 +118,39 @@ describe('@next/font/local', () => {
emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`,
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {
readFile: (path, cb) => cb(null, path),
},
})

expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 100;
font-style: italic;
}
@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 400;
font-style: italic;
}
@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 700;
font-style: italic;
}
@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 400;
Expand Down Expand Up @@ -183,30 +187,31 @@ describe('@next/font/local', () => {
emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`,
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {
readFile: (path, cb) => cb(null, path),
},
})

expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 400;
font-style: italic;
}
@font-face {
font-family: 'font1';
font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 700;
Expand All @@ -226,6 +231,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -242,6 +248,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -258,6 +265,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn().mockResolvedValue(''),
isServer: true,
variableName: 'myFont',
fs: {},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -274,6 +282,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {},
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
Expand All @@ -297,6 +306,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -313,6 +323,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: {},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -339,6 +350,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: { readFile: (path, cb) => cb(null, path) },
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
Expand Down Expand Up @@ -366,6 +378,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(),
resolve: jest.fn(),
isServer: true,
variableName: 'myFont',
fs: { readFile: (path, cb) => cb(null, path) },
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
Expand Down

0 comments on commit d3d8a06

Please sign in to comment.