-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Refactor: Move block fixtures to e2e-tests package #13658
Merged
jorgefilipecosta
merged 3 commits into
master
from
update/extact-block-fixtures-and-utils-to-a-packages
Feb 18, 2019
Merged
Changes from all commits
Commits
Show all changes
3 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
export { | ||
blockNameToFixtureBasename, | ||
getAvailableBlockFixturesBasenames, | ||
getBlockFixtureHTML, | ||
getBlockFixtureJSON, | ||
getBlockFixtureParsedJSON, | ||
getBlockFixtureSerializedHTML, | ||
writeBlockFixtureHTML, | ||
writeBlockFixtureJSON, | ||
writeBlockFixtureParsedJSON, | ||
writeBlockFixtureSerializedHTML, | ||
} from './utils'; |
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,92 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { uniq } from 'lodash'; | ||
|
||
const FIXTURES_DIR = path.join( __dirname, 'blocks' ); | ||
|
||
function readFixtureFile( fixturesDir, filename ) { | ||
try { | ||
return fs.readFileSync( | ||
path.join( fixturesDir, filename ), | ||
'utf8' | ||
); | ||
} catch ( err ) { | ||
return null; | ||
} | ||
} | ||
|
||
function writeFixtureFile( fixturesDir, filename, content ) { | ||
fs.writeFileSync( | ||
path.join( fixturesDir, filename ), | ||
content | ||
); | ||
} | ||
|
||
export function blockNameToFixtureBasename( blockName ) { | ||
return blockName.replace( /\//g, '__' ); | ||
} | ||
|
||
export function getAvailableBlockFixturesBasenames() { | ||
// We expect 4 different types of files for each fixture: | ||
// - fixture.html : original content | ||
// - fixture.parsed.json : parser output | ||
// - fixture.json : blocks structure | ||
// - fixture.serialized.html : re-serialized content | ||
// Get the "base" name for each fixture first. | ||
return uniq( | ||
fs.readdirSync( FIXTURES_DIR ) | ||
.filter( ( f ) => /(\.html|\.json)$/.test( f ) ) | ||
.map( ( f ) => f.replace( /\..+$/, '' ) ) | ||
); | ||
} | ||
|
||
export function getBlockFixtureHTML( basename ) { | ||
const filename = `${ basename }.html`; | ||
return { | ||
filename, | ||
file: readFixtureFile( FIXTURES_DIR, filename ), | ||
}; | ||
} | ||
|
||
export function getBlockFixtureJSON( basename ) { | ||
const filename = `${ basename }.json`; | ||
return { | ||
filename, | ||
file: readFixtureFile( FIXTURES_DIR, filename ), | ||
}; | ||
} | ||
|
||
export function getBlockFixtureParsedJSON( basename ) { | ||
const filename = `${ basename }.parsed.json`; | ||
return { | ||
filename, | ||
file: readFixtureFile( FIXTURES_DIR, filename ), | ||
}; | ||
} | ||
|
||
export function getBlockFixtureSerializedHTML( basename ) { | ||
const filename = `${ basename }.serialized.html`; | ||
return { | ||
filename, | ||
file: readFixtureFile( FIXTURES_DIR, filename ), | ||
}; | ||
} | ||
|
||
export function writeBlockFixtureHTML( basename, fixture ) { | ||
writeFixtureFile( FIXTURES_DIR, `${ basename }.html`, fixture ); | ||
} | ||
|
||
export function writeBlockFixtureJSON( basename, fixture ) { | ||
writeFixtureFile( FIXTURES_DIR, `${ basename }.json`, fixture ); | ||
} | ||
|
||
export function writeBlockFixtureParsedJSON( basename, fixture ) { | ||
writeFixtureFile( FIXTURES_DIR, `${ basename }.parsed.json`, fixture ); | ||
} | ||
|
||
export function writeBlockFixtureSerializedHTML( basename, fixture ) { | ||
writeFixtureFile( FIXTURES_DIR, `${ basename }.serialized.html`, fixture ); | ||
} |
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
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.
I don't think it was a legitimate use-case to disable the rule here. If it's part of the package's public interface, it should be exposed from the root. We shouldn't ever need to path-traverse a module to import.
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.
Agreed in general, however as explained I did it on purpose to avoid exposing those methods at the moment. We will have to maintain them forever so let's test them with our own e2e tests first.
I also left this note:
If we get rid of those integration tests we will also won't need to have those methods exposed as part of the package's public interface. There is another issue which you raised in #13583 and I think noticed in one of the similar PRs which adds a different new block. It seems like those tests are sometimes broken and don't generate the correct output which makes them only confusing. It's very hard to validate them if you don't know exactly how they should behave.