Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
test(e2e): Update e2e template test and snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed May 30, 2018
1 parent 2388d7e commit 9b938cc
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Snapshots InstantSearch.js File content: .gitignore 1`] = `
exports[`Templates InstantSearch.js File content: .gitignore 1`] = `
"# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
Expand All @@ -25,7 +25,7 @@ yarn-debug.log*
yarn-error.log*"
`;

exports[`Snapshots InstantSearch.js File content: README.md 1`] = `
exports[`Templates InstantSearch.js File content: README.md 1`] = `
"# instantsearch.js-app
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._
Expand All @@ -47,7 +47,7 @@ yarn start
\`\`\`"
`;

exports[`Snapshots InstantSearch.js File content: index.html 1`] = `
exports[`Templates InstantSearch.js File content: index.html 1`] = `
"<!DOCTYPE html>
<html lang=\\"en\\">
Expand Down Expand Up @@ -98,7 +98,7 @@ exports[`Snapshots InstantSearch.js File content: index.html 1`] = `
</html>"
`;
exports[`Snapshots InstantSearch.js File content: manifest.webmanifest 1`] = `
exports[`Templates InstantSearch.js File content: manifest.webmanifest 1`] = `
"{
\\"short_name\\": \\"instantsearch.js-app\\",
\\"name\\": \\"instantsearch.js-app Sample\\",
Expand All @@ -116,7 +116,7 @@ exports[`Snapshots InstantSearch.js File content: manifest.webmanifest 1`] = `
}"
`;
exports[`Snapshots InstantSearch.js File content: package.json 1`] = `
exports[`Templates InstantSearch.js File content: package.json 1`] = `
"{
\\"name\\": \\"instantsearch.js-app\\",
\\"version\\": \\"1.0.0\\",
Expand All @@ -131,7 +131,7 @@ exports[`Snapshots InstantSearch.js File content: package.json 1`] = `
}"
`;
exports[`Snapshots InstantSearch.js File content: src/app.css 1`] = `
exports[`Templates InstantSearch.js File content: src/app.css 1`] = `
"em {
background: cyan;
font-style: normal;
Expand Down Expand Up @@ -203,7 +203,7 @@ exports[`Snapshots InstantSearch.js File content: src/app.css 1`] = `
}"
`;
exports[`Snapshots InstantSearch.js File content: src/app.js 1`] = `
exports[`Templates InstantSearch.js File content: src/app.js 1`] = `
"/* global instantsearch */
const search = instantsearch({
Expand Down Expand Up @@ -252,7 +252,7 @@ search.addWidget(
search.start();"
`;
exports[`Snapshots InstantSearch.js File content: src/index.css 1`] = `
exports[`Templates InstantSearch.js File content: src/index.css 1`] = `
"body,
h1 {
margin: 0;
Expand All @@ -265,7 +265,7 @@ body {
}"
`;
exports[`Snapshots InstantSearch.js Folder structure: contains the right files 1`] = `
exports[`Templates InstantSearch.js Folder structure: contains the right files 1`] = `
Array [
".gitignore",
"README.md",
Expand All @@ -279,7 +279,7 @@ Array [
]
`;
exports[`Snapshots React InstantSearch File content: .gitignore 1`] = `
exports[`Templates React InstantSearch File content: .gitignore 1`] = `
"# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
Expand All @@ -303,7 +303,7 @@ yarn-debug.log*
yarn-error.log*"
`;
exports[`Snapshots React InstantSearch File content: README.md 1`] = `
exports[`Templates React InstantSearch File content: README.md 1`] = `
"# react-instantsearch-app
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._
Expand All @@ -325,7 +325,7 @@ yarn start
\`\`\`"
`;
exports[`Snapshots React InstantSearch File content: package.json 1`] = `
exports[`Templates React InstantSearch File content: package.json 1`] = `
"{
\\"name\\": \\"react-instantsearch-app\\",
\\"version\\": \\"1.0.0\\",
Expand All @@ -346,7 +346,7 @@ exports[`Snapshots React InstantSearch File content: package.json 1`] = `
}"
`;
exports[`Snapshots React InstantSearch File content: public/index.html 1`] = `
exports[`Templates React InstantSearch File content: public/index.html 1`] = `
"<!DOCTYPE html>
<html lang=\\"en\\">
Expand Down Expand Up @@ -378,7 +378,7 @@ exports[`Snapshots React InstantSearch File content: public/index.html 1`] = `
</html>"
`;
exports[`Snapshots React InstantSearch File content: public/manifest.json 1`] = `
exports[`Templates React InstantSearch File content: public/manifest.json 1`] = `
"{
\\"short_name\\": \\"react-instantsearch-app\\",
\\"name\\": \\"react-instantsearch-app Sample\\",
Expand All @@ -396,7 +396,7 @@ exports[`Snapshots React InstantSearch File content: public/manifest.json 1`] =
}"
`;
exports[`Snapshots React InstantSearch File content: src/App.css 1`] = `
exports[`Templates React InstantSearch File content: src/App.css 1`] = `
"em {
background: cyan;
font-style: normal;
Expand Down Expand Up @@ -453,7 +453,7 @@ exports[`Snapshots React InstantSearch File content: src/App.css 1`] = `
}"
`;
exports[`Snapshots React InstantSearch File content: src/App.js 1`] = `
exports[`Templates React InstantSearch File content: src/App.js 1`] = `
"import React, { Component } from 'react';
import {
InstantSearch,
Expand Down Expand Up @@ -525,7 +525,7 @@ Hit.propTypes = {
export default App;"
`;
exports[`Snapshots React InstantSearch File content: src/index.css 1`] = `
exports[`Templates React InstantSearch File content: src/index.css 1`] = `
"body,
h1 {
margin: 0;
Expand All @@ -538,7 +538,7 @@ body {
}"
`;
exports[`Snapshots React InstantSearch File content: src/index.js 1`] = `
exports[`Templates React InstantSearch File content: src/index.js 1`] = `
"import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
Expand All @@ -547,7 +547,7 @@ import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));"
`;
exports[`Snapshots React InstantSearch Folder structure: contains the right files 1`] = `
exports[`Templates React InstantSearch Folder structure: contains the right files 1`] = `
Array [
".gitignore",
"README.md",
Expand All @@ -562,7 +562,7 @@ Array [
]
`;
exports[`Snapshots Vue InstantSearch File content: .babelrc 1`] = `
exports[`Templates Vue InstantSearch File content: .babelrc 1`] = `
"{
\\"presets\\": [
[\\"env\\", { \\"modules\\": false }],
Expand All @@ -571,15 +571,15 @@ exports[`Snapshots Vue InstantSearch File content: .babelrc 1`] = `
}"
`;
exports[`Snapshots Vue InstantSearch File content: .gitignore 1`] = `
exports[`Templates Vue InstantSearch File content: .gitignore 1`] = `
"node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log
dist/"
`;
exports[`Snapshots Vue InstantSearch File content: README.md 1`] = `
exports[`Templates Vue InstantSearch File content: README.md 1`] = `
"# vue-instantsearch-app
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._
Expand All @@ -601,7 +601,7 @@ yarn start
\`\`\`"
`;
exports[`Snapshots Vue InstantSearch File content: index.html 1`] = `
exports[`Templates Vue InstantSearch File content: index.html 1`] = `
"<!DOCTYPE html>
<html lang=\\"en\\">
Expand Down Expand Up @@ -635,7 +635,7 @@ exports[`Snapshots Vue InstantSearch File content: index.html 1`] = `
</html>"
`;
exports[`Snapshots Vue InstantSearch File content: manifest.json 1`] = `
exports[`Templates Vue InstantSearch File content: manifest.json 1`] = `
"{
\\"short_name\\": \\"vue-instantsearch-app\\",
\\"name\\": \\"vue-instantsearch-app Sample\\",
Expand All @@ -653,7 +653,7 @@ exports[`Snapshots Vue InstantSearch File content: manifest.json 1`] = `
}"
`;
exports[`Snapshots Vue InstantSearch File content: package.json 1`] = `
exports[`Templates Vue InstantSearch File content: package.json 1`] = `
"{
\\"name\\": \\"vue-instantsearch-app\\",
\\"version\\": \\"1.0.0\\",
Expand Down Expand Up @@ -682,7 +682,7 @@ exports[`Snapshots Vue InstantSearch File content: package.json 1`] = `
}"
`;
exports[`Snapshots Vue InstantSearch File content: src/App.vue 1`] = `
exports[`Templates Vue InstantSearch File content: src/App.vue 1`] = `
"<template>
<div>
<header class=\\"header\\">
Expand Down Expand Up @@ -821,7 +821,7 @@ em {
</style>"
`;

exports[`Snapshots Vue InstantSearch File content: src/main.js 1`] = `
exports[`Templates Vue InstantSearch File content: src/main.js 1`] = `
"import Vue from 'vue';
import App from './App.vue';
import InstantSearch from 'vue-instantsearch';
Expand All @@ -834,7 +834,7 @@ new Vue({
});"
`;

exports[`Snapshots Vue InstantSearch File content: webpack.config.js 1`] = `
exports[`Templates Vue InstantSearch File content: webpack.config.js 1`] = `
"const path = require('path');
const webpack = require('webpack');
Expand Down Expand Up @@ -913,7 +913,7 @@ if (process.env.NODE_ENV === 'production') {
}"
`;

exports[`Snapshots Vue InstantSearch Folder structure: contains the right files 1`] = `
exports[`Templates Vue InstantSearch Folder structure: contains the right files 1`] = `
Array [
".babelrc",
".gitignore",
Expand Down
104 changes: 104 additions & 0 deletions scripts/e2e-templates.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const walkSync = require('walk-sync');
const { toMatchImageSnapshot } = require('jest-image-snapshot');

expect.extend({ toMatchImageSnapshot });

const templatesFolder = path.join(__dirname, '../templates');
const templates = fs
.readdirSync(templatesFolder)
.map(name => path.join(templatesFolder, name))
.filter(source => fs.lstatSync(source).isDirectory());

describe('Templates', () => {
templates.forEach(templatePath => {
const templateName = path.basename(templatePath);
const templateConfig = require(`${templatePath}/.template.js`);

describe(templateName, () => {
let temporaryDirectory;
let appPath;
let configFilePath;
let generatedFiles;

beforeAll(() => {
temporaryDirectory = execSync(
'mktemp -d 2>/dev/null || mktemp -d -t "appPath"'
)
.toString()
.trim();

appPath = `${temporaryDirectory}/${templateConfig.appName}`;

const config = {
name: `${templateConfig.appName}`,
template: templateName,
libraryVersion: '1.0.0',
appId: 'appId',
apiKey: 'apiKey',
indexName: 'indexName',
searchPlaceholder: 'Search placeholder',
mainAttribute: 'mainAttribute',
attributesForFaceting: ['facet1', 'facet2'],
};

configFilePath = `${temporaryDirectory}/${
templateConfig.appName
}.config.json`;

fs.writeFileSync(configFilePath, JSON.stringify(config));

execSync(
`yarn start ${appPath} \
--config ${configFilePath} \
--no-installation`,
{ stdio: 'ignore' }
);

const ignoredFiles = fs
.readFileSync(`${appPath}/.gitignore`)
.toString()
.split('\n')
.filter(line => !line.startsWith('#'))
.filter(Boolean)
.concat('.DS_Store');

generatedFiles = walkSync(appPath, {
directories: false,
ignore: ignoredFiles,
});
});

afterAll(() => {
execSync(`rm -rf "${temporaryDirectory}"`);
});

test('Folder structure', () => {
expect(generatedFiles).toMatchSnapshot('contains the right files');
});

test('File content', () => {
generatedFiles.forEach(filePath => {
if (['.png', '.ico', '.jpg'].includes(filePath.slice(-4))) {
const image = fs.readFileSync(`${templatePath}/${filePath}`);

expect(image).toMatchImageSnapshot({
customSnapshotIdentifier: `e2e-installs-${
templateConfig.templateName
}-${path.basename(filePath)}`,
});
} else {
const fileContent = fs
.readFileSync(`${appPath}/${filePath}`)
.toString()
.trim();

expect(fileContent).toMatchSnapshot(filePath);
}
});
});
});
});
});

0 comments on commit 9b938cc

Please sign in to comment.