-
Notifications
You must be signed in to change notification settings - Fork 46.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[attribute-behavior] Snapshot test #10587
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
2,668 changes: 2,668 additions & 0 deletions
2,668
fixtures/attribute-behavior/src/attributeBehavior.js
Large diffs are not rendered by default.
Oops, something went wrong.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably a better way to do this but idk what it is :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I really want is a callback that says "Hey CRA is serving your app now, go ahead and run your tests."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote do a production build and run at as a static for serve, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.