Skip to content

Commit

Permalink
Check CSS Test Output (#10237)
Browse files Browse the repository at this point in the history
* Check CSS Test Output

* replace more

* Fix tests

* check code

* Add code check

* Check codes everywhere
  • Loading branch information
Timer committed Jan 23, 2020
1 parent b747f7b commit bf31b4e
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 101 deletions.
33 changes: 24 additions & 9 deletions test/integration/css-customization/test/index.test.js
Expand Up @@ -16,8 +16,12 @@ describe('CSS Customization', () => {
await remove(join(appDir, '.next'))
})

it('should build successfully', async () => {
await nextBuild(appDir)
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 () => {
Expand Down Expand Up @@ -78,8 +82,12 @@ describe('Legacy Next-CSS Customization', () => {
await remove(join(appDir, '.next'))
})

it('should build successfully', async () => {
await nextBuild(appDir)
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 () => {
Expand All @@ -103,8 +111,12 @@ describe('CSS Customization Array', () => {
await remove(join(appDir, '.next'))
})

it('should build successfully', async () => {
await nextBuild(appDir)
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 () => {
Expand Down Expand Up @@ -168,9 +180,12 @@ describe('Bad CSS Customization', () => {
await remove(join(appDir, '.next'))
})

it('should build successfully', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })

it('should compile successfully', async () => {
const { stdout, stderr } = await nextBuild(appDir, [], {
stdout: true,
stderr: true,
})
expect(stdout).toMatch(/Compiled successfully/)
expect(stderr).toMatch(/field which is not supported.*?sourceMap/)
;[
'postcss-modules-values',
Expand Down
64 changes: 56 additions & 8 deletions test/integration/css-features/test/index.test.js
Expand Up @@ -11,9 +11,18 @@ const fixturesDir = join(__dirname, '../fixtures')
describe('Browserslist: Old', () => {
const appDir = join(fixturesDir, 'browsers-old')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand All @@ -34,9 +43,18 @@ describe('Browserslist: Old', () => {
describe('Browserslist: New', () => {
const appDir = join(fixturesDir, 'browsers-new')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand All @@ -57,9 +75,18 @@ describe('Browserslist: New', () => {
describe('Custom Properties: Pass-Through IE11', () => {
const appDir = join(fixturesDir, 'cp-ie-11')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand All @@ -80,9 +107,18 @@ describe('Custom Properties: Pass-Through IE11', () => {
describe('Custom Properties: Pass-Through Modern', () => {
const appDir = join(fixturesDir, 'cp-modern')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand All @@ -108,9 +144,10 @@ describe('Custom Properties: Fail for :root {} in CSS Modules', () => {
})

it('should fail to build', async () => {
const { stderr } = await nextBuild(appDir, [], {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('pages/styles.module.css')
expect(stderr).toContain('CssSyntax error: Selector ":root" is not pure')
Expand All @@ -125,9 +162,10 @@ describe('Custom Properties: Fail for global element in CSS Modules', () => {
})

it('should fail to build', async () => {
const { stderr } = await nextBuild(appDir, [], {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('pages/styles.module.css')
expect(stderr).toContain('CssSyntax error: Selector "h1" is not pure')
Expand All @@ -137,9 +175,18 @@ describe('Custom Properties: Fail for global element in CSS Modules', () => {
describe('CSS Modules: Import Global CSS', () => {
const appDir = join(fixturesDir, 'module-import-global')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand All @@ -165,9 +212,10 @@ describe('CSS Modules: Importing Invalid Global CSS', () => {
})

it('should fail to build', async () => {
const { stderr } = await nextBuild(appDir, [], {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('pages/styles.module.css')
expect(stderr).toContain('CssSyntax error: Selector "a" is not pure')
Expand Down
85 changes: 76 additions & 9 deletions test/integration/css-modules/test/index.test.js
Expand Up @@ -23,16 +23,25 @@ describe('Basic CSS Module Support', () => {

let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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')

Expand Down Expand Up @@ -70,16 +79,25 @@ describe('3rd Party CSS Module Support', () => {

let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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')

Expand Down Expand Up @@ -141,16 +159,25 @@ describe('Has CSS Module in computed styles in Production', () => {

let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 have CSS for page', async () => {
const browser = await webdriver(appPort, '/')

Expand Down Expand Up @@ -216,9 +243,10 @@ describe('Invalid CSS Module Usage in node_modules', () => {
})

it('should fail to build', async () => {
const { stderr } = await nextBuild(appDir, [], {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.module.css')
expect(stderr).toMatch(
Expand All @@ -236,9 +264,10 @@ describe('Invalid CSS Module Usage in node_modules', () => {
})

it('should fail to build', async () => {
const { stderr } = await nextBuild(appDir, [], {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.css')
expect(stderr).toMatch(
Expand All @@ -257,15 +286,25 @@ describe('Valid CSS Module Usage from within node_modules', () => {

let appPort
let app
let stdout
let code
beforeAll(async () => {
await nextBuild(appDir)
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 prerendered with relevant data`, async () => {
const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
Expand Down Expand Up @@ -300,15 +339,25 @@ describe('Valid Nested CSS Module Usage from within node_modules', () => {

let appPort
let app
let stdout
let code
beforeAll(async () => {
await nextBuild(appDir)
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 prerendered with relevant data`, async () => {
const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
Expand Down Expand Up @@ -338,9 +387,18 @@ describe('CSS Module Composes Usage (Basic)', () => {
// This is a very bad feature. Do not use it.
const appDir = join(fixturesDir, 'composes-basic')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand All @@ -362,9 +420,18 @@ describe('CSS Module Composes Usage (External)', () => {
// This is a very bad feature. Do not use it.
const appDir = join(fixturesDir, 'composes-external')

let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
;({ 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 () => {
Expand Down

0 comments on commit bf31b4e

Please sign in to comment.