-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move scss tests into individual directories
- Loading branch information
1 parent
5be8135
commit 0050a02
Showing
44 changed files
with
1,567 additions
and
1,391 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
test/integration/scss/scss-fixtures/3rd-party-module/3rd-party-module.test.js
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-env jest */ | ||
|
||
import cheerio from 'cheerio' | ||
import { readdir, readFile, remove } from 'fs-extra' | ||
import { | ||
findPort, | ||
killApp, | ||
nextBuild, | ||
nextStart, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('3rd Party CSS Module Support', () => { | ||
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { | ||
const appDir = __dirname | ||
|
||
let appPort | ||
let app | ||
let stdout | ||
let code | ||
beforeAll(async () => { | ||
await remove(join(appDir, '.next')) | ||
;({ code, stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
})) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(async () => { | ||
await killApp(app) | ||
}) | ||
|
||
it('should have compiled successfully', () => { | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it(`should've emitted a single CSS file`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssFiles = files.filter((f) => /\.css$/.test(f)) | ||
|
||
expect(cssFiles.length).toBe(1) | ||
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') | ||
|
||
expect( | ||
cssContent.replace(/\/\*.*?\*\//g, '').trim() | ||
).toMatchInlineSnapshot( | ||
`".index_foo__72b4D{position:relative}.index_foo__72b4D .bar,.index_foo__72b4D .baz{height:100%;overflow:hidden}.index_foo__72b4D .lol,.index_foo__72b4D>.lel{width:80%}"` | ||
) | ||
}) | ||
|
||
it(`should've injected the CSS on server render`, async () => { | ||
const content = await renderViaHTTP(appPort, '/') | ||
const $ = cheerio.load(content) | ||
|
||
const cssPreload = $('link[rel="preload"][as="style"]') | ||
expect(cssPreload.length).toBe(1) | ||
expect(cssPreload.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/) | ||
|
||
const cssSheet = $('link[rel="stylesheet"]') | ||
expect(cssSheet.length).toBe(1) | ||
expect(cssSheet.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/) | ||
|
||
expect($('#verify-div').attr('class')).toMatchInlineSnapshot( | ||
`"index_foo__72b4D"` | ||
) | ||
}) | ||
}) | ||
}) |
35 changes: 35 additions & 0 deletions
35
...egration/scss/scss-fixtures/basic-module-include-paths/basic-module-include-paths.test.js
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-env jest */ | ||
|
||
import { readdir, readFile, remove } from 'fs-extra' | ||
import { nextBuild } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('Basic Module Include Paths Support', () => { | ||
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { | ||
const appDir = __dirname | ||
|
||
beforeAll(async () => { | ||
await remove(join(appDir, '.next')) | ||
}) | ||
|
||
it('should compile successfully', async () => { | ||
const { code, stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
}) | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it(`should've emitted a single CSS file`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssFiles = files.filter((f) => /\.css$/.test(f)) | ||
|
||
expect(cssFiles.length).toBe(1) | ||
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain( | ||
'color:red' | ||
) | ||
}) | ||
}) | ||
}) |
35 changes: 35 additions & 0 deletions
35
...ntegration/scss/scss-fixtures/basic-module-prepend-data/basic-module-prepend-data.test.js
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-env jest */ | ||
|
||
import { readdir, readFile, remove } from 'fs-extra' | ||
import { nextBuild } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('Basic Module Prepend Data Support', () => { | ||
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { | ||
const appDir = __dirname | ||
|
||
beforeAll(async () => { | ||
await remove(join(appDir, '.next')) | ||
}) | ||
|
||
it('should compile successfully', async () => { | ||
const { code, stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
}) | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it(`should've emitted a single CSS file`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssFiles = files.filter((f) => /\.css$/.test(f)) | ||
|
||
expect(cssFiles.length).toBe(1) | ||
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain( | ||
'color:red' | ||
) | ||
}) | ||
}) | ||
}) |
70 changes: 70 additions & 0 deletions
70
test/integration/scss/scss-fixtures/basic-module/basic-module.test.js
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* eslint-env jest */ | ||
|
||
import cheerio from 'cheerio' | ||
import { readdir, readFile, remove } from 'fs-extra' | ||
import { | ||
findPort, | ||
killApp, | ||
nextBuild, | ||
nextStart, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('Basic SCSS Module Support', () => { | ||
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { | ||
const appDir = __dirname | ||
|
||
let appPort | ||
let app | ||
let stdout | ||
let code | ||
beforeAll(async () => { | ||
await remove(join(appDir, '.next')) | ||
;({ code, stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
})) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(async () => { | ||
await killApp(app) | ||
}) | ||
|
||
it('should have compiled successfully', () => { | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it(`should've emitted a single CSS file`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssFiles = files.filter((f) => /\.css$/.test(f)) | ||
|
||
expect(cssFiles.length).toBe(1) | ||
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') | ||
|
||
expect( | ||
cssContent.replace(/\/\*.*?\*\//g, '').trim() | ||
).toMatchInlineSnapshot(`".index_redText__zXafh{color:red}"`) | ||
}) | ||
|
||
it(`should've injected the CSS on server render`, async () => { | ||
const content = await renderViaHTTP(appPort, '/') | ||
const $ = cheerio.load(content) | ||
|
||
const cssPreload = $('link[rel="preload"][as="style"]') | ||
expect(cssPreload.length).toBe(1) | ||
expect(cssPreload.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/) | ||
|
||
const cssSheet = $('link[rel="stylesheet"]') | ||
expect(cssSheet.length).toBe(1) | ||
expect(cssSheet.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/) | ||
|
||
expect($('#verify-red').attr('class')).toMatchInlineSnapshot( | ||
`"index_redText__zXafh"` | ||
) | ||
}) | ||
}) | ||
}) |
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
76 changes: 76 additions & 0 deletions
76
...ntegration/scss/scss-fixtures/compilation-and-prefixing/compilation-and-prefixing.test.js
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* eslint-env jest */ | ||
|
||
import { readdir, readFile, remove } from 'fs-extra' | ||
import { nextBuild } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('SCSS Support', () => { | ||
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { | ||
describe('CSS Compilation and Prefixing', () => { | ||
const appDir = __dirname | ||
|
||
beforeAll(async () => { | ||
await remove(join(appDir, '.next')) | ||
}) | ||
|
||
it('should compile successfully', async () => { | ||
const { code, stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
}) | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it(`should've compiled and prefixed`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssFiles = files.filter((f) => /\.css$/.test(f)) | ||
|
||
expect(cssFiles.length).toBe(1) | ||
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') | ||
expect( | ||
cssContent.replace(/\/\*.*?\*\//g, '').trim() | ||
).toMatchInlineSnapshot( | ||
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"` | ||
) | ||
|
||
// Contains a source map | ||
expect(cssContent).toMatch(/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//) | ||
}) | ||
|
||
it(`should've emitted a source map`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssMapFiles = files.filter((f) => /\.css\.map$/.test(f)) | ||
|
||
expect(cssMapFiles.length).toBe(1) | ||
const cssMapContent = ( | ||
await readFile(join(cssFolder, cssMapFiles[0]), 'utf8') | ||
).trim() | ||
|
||
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) | ||
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` | ||
{ | ||
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA", | ||
"sourcesContent": [ | ||
"$var: red; | ||
.redText { | ||
::placeholder { | ||
color: $var; | ||
} | ||
} | ||
.flex-parsing { | ||
flex: 0 0 calc(50% - var(--vertical-gutter)); | ||
} | ||
", | ||
], | ||
"version": 3, | ||
} | ||
`) | ||
}) | ||
}) | ||
}) | ||
}) |
41 changes: 41 additions & 0 deletions
41
test/integration/scss/scss-fixtures/composes-basic/composes-basic.test.js
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-env jest */ | ||
|
||
import { readdir, readFile, remove } from 'fs-extra' | ||
import { nextBuild } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('CSS Module Composes Usage (Basic)', () => { | ||
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { | ||
// This is a very bad feature. Do not use it. | ||
const appDir = __dirname | ||
let stdout | ||
let code | ||
beforeAll(async () => { | ||
await remove(join(appDir, '.next')) | ||
;({ code, stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
})) | ||
}) | ||
|
||
it('should have compiled successfully', () => { | ||
expect(code).toBe(0) | ||
expect(stdout).toMatch(/Compiled successfully/) | ||
}) | ||
|
||
it(`should've emitted a single CSS file`, async () => { | ||
const cssFolder = join(appDir, '.next/static/css') | ||
|
||
const files = await readdir(cssFolder) | ||
const cssFiles = files.filter((f) => /\.css$/.test(f)) | ||
|
||
expect(cssFiles.length).toBe(1) | ||
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') | ||
|
||
expect( | ||
cssContent.replace(/\/\*.*?\*\//g, '').trim() | ||
).toMatchInlineSnapshot( | ||
`".index_className__OLWEh{background:red;color:#ff0}.index_subClass__Z_IFg{background:blue}"` | ||
) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.