-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot test for attribute table
Same data as the attribute table, but in the form of a snapshot. Uses puppeteer to run headless Chromium.
- Loading branch information
Showing
7 changed files
with
12,202 additions
and
4 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
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,73 @@ | ||
/* eslint-disable */ | ||
|
||
import { | ||
getCanonicalizedValue, | ||
getRenderedAttributeValue, | ||
attributes, | ||
types, | ||
} from './attributeBehavior'; | ||
|
||
const React = global.React; | ||
const {Component} = React; | ||
|
||
const ReactDOM16 = global.ReactDOM16; | ||
const ReactDOMServer16 = global.ReactDOMServer16; | ||
|
||
function getUniqueKey(t, key, depth = 1) { | ||
if (depth !== 1) { | ||
key = `${key} (variant ${depth})`; | ||
} | ||
if (t.has(key)) { | ||
return getUniqueKey(t, key, depth + 1); | ||
} | ||
return key; | ||
} | ||
|
||
function test() { | ||
let log = ''; | ||
for (let attribute of attributes) { | ||
log += `${attribute.name}\n`; | ||
for (let type of types) { | ||
const result = getRenderedAttributeValue( | ||
React, | ||
ReactDOM16, | ||
ReactDOMServer16, | ||
attribute, | ||
type | ||
); | ||
|
||
const { | ||
didError, | ||
didWarn, | ||
canonicalResult, | ||
canonicalDefaultValue, | ||
ssrHasSameBehavior, | ||
ssrHasSameBehaviorExceptWarnings, | ||
} = result; | ||
|
||
let descriptions = []; | ||
if (canonicalResult === canonicalDefaultValue) { | ||
descriptions.push('NO CHANGE'); | ||
} | ||
if (didError) { | ||
descriptions.push('ERROR'); | ||
} | ||
if (didWarn) { | ||
descriptions.push('WARN'); | ||
} | ||
if (!ssrHasSameBehavior) { | ||
if (ssrHasSameBehaviorExceptWarnings) { | ||
descriptions.push('SSR WARNS'); | ||
} else { | ||
descriptions.push('SSR DEVIATION'); | ||
} | ||
} | ||
|
||
log += `\t${type.name} -> ${canonicalResult} ${descriptions.join(', ')}\n`; | ||
} | ||
} | ||
|
||
return log; | ||
} | ||
|
||
window.test = test; |
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
82 changes: 82 additions & 0 deletions
82
src/renderers/dom/shared/__tests__/DOMAttributeBehavior-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,82 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags'); | ||
const puppeteer = require('puppeteer'); | ||
|
||
let child; | ||
|
||
describe('DOMAttributeBehavior', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
}); | ||
|
||
afterEach(() => { | ||
if (child) { | ||
// Kill the child process and its subprocesses | ||
process.kill(-child.pid, 'SIGINT'); | ||
} | ||
}); | ||
|
||
async function testAttributeBehavior(url) { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
await page.goto(url); | ||
const result = await page.evaluate(() => { | ||
return window.test(); | ||
}); | ||
expect(result).toMatchSnapshot(); | ||
} | ||
|
||
it( | ||
'works', | ||
done => { | ||
if (!ReactDOMFeatureFlags.useFiber) { | ||
done(); | ||
return; | ||
} | ||
const path = require('path'); | ||
const {execSync, spawn} = require('child_process'); | ||
|
||
const cwd = path.resolve(process.cwd(), 'fixtures/attribute-behavior'); | ||
|
||
execSync('yarn', {cwd}); | ||
|
||
process.env.BROWSER = 'none'; | ||
process.env.PORT = 9292; | ||
|
||
child = spawn('yarn', ['start'], {cwd, detached: true}); | ||
|
||
let didStartTest = false; | ||
child.stdout.on('data', data => { | ||
const str = data.toString('utf8'); | ||
if (str.includes('Failed')) { | ||
console.error('Failure on CRA startup'); | ||
done(); | ||
return; | ||
} | ||
|
||
if (!didStartTest && str.includes('http://localhost:9292/')) { | ||
didStartTest = true; | ||
testAttributeBehavior('http://localhost:9292/headless') | ||
.then(() => done()) | ||
.catch(error => { | ||
console.error(error); | ||
done(); | ||
}); | ||
} | ||
}); | ||
}, | ||
30000, | ||
); | ||
}); |
Oops, something went wrong.