Skip to content
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

Improvements on end-to-end tests #2840

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Speed up before hook
  • Loading branch information
felipeelia committed Jun 14, 2022
commit c1f45555eb56eab1bcf099926ce53452ff14d01d
32 changes: 1 addition & 31 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,37 +158,7 @@ Cypress.Commands.add('publishPost', (postData) => {
});

Cypress.Commands.add('updateFeatures', (newFeaturesValues = {}) => {
const features = {
search: {
active: 1,
highlight_enabled: true,
highlight_excerpt: true,
highlight_tag: 'mark',
highlight_color: '#157d84',
},
related_posts: {
active: 1,
},
facets: {
active: 1,
},
searchordering: {
active: 1,
},
autosuggest: {
active: 1,
},
woocommerce: {
active: 0,
},
protected_content: {
active: 0,
},
users: {
active: 0,
},
...newFeaturesValues,
};
const features = Object.assign({}, cy.elasticPress.defaultFeatures, ...newFeaturesValues);

const escapedFeatures = JSON.stringify(features);

Expand Down
54 changes: 21 additions & 33 deletions tests/cypress/support/global-hooks.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
window.indexNames = null;

let setFeatures = false;

before(() => {
// Clear sync from previous tests.
cy.wpCli('wp elasticpress clear-index');
cy.wpCliEval(
`
// Clear any stuck sync process.
\\ElasticPress\\IndexHelper::factory()->clear_index_meta();

if (!window.indexNames) {
cy.wpCli('wp elasticpress get-indexes').then((wpCliResponse) => {
window.indexNames = JSON.parse(wpCliResponse.stdout);
});
}
$features = json_decode( '${JSON.stringify(cy.elasticPress.defaultFeatures)}', true );

if ( ! \\ElasticPress\\Utils\\is_epio() ) {
$host = \\ElasticPress\\Utils\\get_host();
$host = str_replace( '172.17.0.1', 'localhost', $host );
$index_name = \\ElasticPress\\Indexables::factory()->get( 'post' )->get_index_name();
$as_endpoint_url = $host . $index_name . '/_search';

$features['autosuggest']['endpoint_url'] = $as_endpoint_url;
}

if (!setFeatures) {
cy.wpCliEval(
`if ( \\ElasticPress\\Utils\\is_epio() ) {
exit;
}
$host = \\ElasticPress\\Utils\\get_host();
$host = str_replace( '172.17.0.1', 'localhost', $host );
$index_name = \\ElasticPress\\Indexables::factory()->get( 'post' )->get_index_name();
echo $host . $index_name . '/_search';
`,
).then((searchEndpointUrl) => {
if (searchEndpointUrl.stdout === '') {
cy.updateFeatures();
} else {
cy.updateFeatures({
autosuggest: {
active: 1,
endpoint_url: searchEndpointUrl.stdout,
},
});
}
});
setFeatures = true;
}
update_option( 'ep_feature_settings', $features );

WP_CLI::runcommand('elasticpress get-indexes');
`,
).then((wpCliResponse) => {
window.indexNames = JSON.parse(wpCliResponse.stdout);
});
});

afterEach(() => {
Expand Down
33 changes: 33 additions & 0 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,36 @@ import './global-hooks';

// Alternatively you can use CommonJS syntax:
// require('./commands')

cy.elasticPress = {
defaultFeatures: {
search: {
active: 1,
highlight_enabled: true,
highlight_excerpt: true,
highlight_tag: 'mark',
highlight_color: '#157d84',
},
related_posts: {
active: 1,
},
facets: {
active: 1,
},
searchordering: {
active: 1,
},
autosuggest: {
active: 1,
},
woocommerce: {
active: 0,
},
protected_content: {
active: 0,
},
users: {
active: 0,
},
},
};