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

test(e2e): Add local npm registry for testing #134

Merged
merged 34 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cde71b7
test(e2e): Add local npm registry for testing
louis-bompart Mar 31, 2021
822100c
Merge branch 'master' into CDX-212
louis-bompart Mar 31, 2021
b3c411e
stabilize
louis-bompart Apr 1, 2021
229676a
stabilize angular
louis-bompart Apr 1, 2021
79f037e
merge
louis-bompart Apr 1, 2021
7d9ac17
disable react tests
louis-bompart Apr 1, 2021
b6ce3a3
wrap process management
louis-bompart Apr 6, 2021
7b426d6
Merge branch 'master' into CDX-212
louis-bompart Apr 6, 2021
18bfb0e
all working
louis-bompart Apr 7, 2021
a2ecaf8
Merge remote-tracking branch 'origin/CDX-212' into CDX-212
louis-bompart Apr 7, 2021
7f35436
big timeout for slow CI
louis-bompart Apr 7, 2021
475089e
better server started detection condition
louis-bompart Apr 7, 2021
c1a5fe5
logging react toremove
louis-bompart Apr 7, 2021
b84f670
Revert "logging react toremove"
louis-bompart Apr 7, 2021
02a0994
logging react toremove
louis-bompart Apr 7, 2021
5d0e3ea
add alternative exit condition for react setup
louis-bompart Apr 7, 2021
51ccbb6
Revert "logging react toremove"
louis-bompart Apr 7, 2021
ac17bb3
rm timeout of angular
louis-bompart Apr 7, 2021
e277ba0
add openNewPage in react
louis-bompart Apr 7, 2021
5d43c60
revert unwanted changes in entrypoint
louis-bompart Apr 7, 2021
d4cc562
try no sudo
louis-bompart Apr 7, 2021
76c1f9d
sudo with no newline
louis-bompart Apr 7, 2021
824c004
Add better build detection for all test suites.
louis-bompart Apr 7, 2021
2b74d0b
check pid is a number
louis-bompart Apr 7, 2021
bcfb005
cleaning 1
louis-bompart Apr 7, 2021
dac402a
Merge branch 'master' into CDX-212
louis-bompart Apr 7, 2021
650c433
revert to non schematic
louis-bompart Apr 7, 2021
75615a4
leaner verdaccio config
louis-bompart Apr 7, 2021
7bbb0f6
refactor opennewpage
louis-bompart Apr 7, 2021
66f98c7
bubble up error
louis-bompart Apr 7, 2021
c9b8cdd
errorhandling
louis-bompart Apr 7, 2021
0cd9f07
debug
louis-bompart Apr 7, 2021
41377c9
error bubbling
louis-bompart Apr 7, 2021
eb54b50
muzzle yarn
louis-bompart Apr 8, 2021
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
19 changes: 1 addition & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,9 @@ jobs:
- name: Build CLI
working-directory: ./packages/cli
run: tsc -b
- name: Set the template version
run: |
node scripts/store-next-test-version.js --variable=UI_TEMPLATE_VERSION --output=$GITHUB_ENV
- name: Bump template versions
run: |
echo "E2E tests should target template version ${{ env.UI_TEMPLATE_VERSION }}"
echo "//registry.npmjs.org/:_authToken=${{ env.NPM_TOKEN }}" > ~/.npmrc
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
npm run npm:bump:template -- -- ${{ env.UI_TEMPLATE_VERSION }}
npm run npm:publish:template
node scripts/wait-for-published-packages.js -v ${{ env.UI_TEMPLATE_VERSION }}
- uses: actions/upload-artifact@v2
if: failure()
with:
name: npm-logs
path: /home/runner/.npm/_logs/*debug.log
- name: End-to-end Tests
working-directory: ./packages/cli-e2e
run: |
echo "Running E2E tests with version ${{ env.UI_TEMPLATE_VERSION }}"
npm run test-e2e
run: npm run test-e2e
- uses: actions/upload-artifact@v2
with:
name: test-screenshots
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Coveo schematic for angular",
"scripts": {
"test": "npm run build && jasmine dist/**/*_spec.js",
"build": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.schematic.json",
Copy link
Collaborator Author

@louis-bompart louis-bompart Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"prebuild": "node ./scripts/clean.js",
"postbuild": "node ./scripts/setup.js",
"prepublishOnly": "npm run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/search-token-server/rules/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function startProxyServerFromRootApp(_options: CoveoSchema): Rule {
const packageJson = JSON.parse(packageJsonBuffer.toString());

packageJson.scripts['start'] =
'concurrently "npm run start-server" "ng serve"';
'concurrently --raw "npm run start-server" "ng serve"';
packageJson.scripts['start-server'] = 'node ./scripts/start-server.js';

tree.overwrite(
Expand Down
73 changes: 64 additions & 9 deletions packages/cli-e2e/__tests__/angular.specs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import retry from 'async-retry';

import type {ChildProcessWithoutNullStreams} from 'child_process';
import {ChildProcessWithoutNullStreams, spawn} from 'child_process';
import type {HTTPRequest, Browser, Page} from 'puppeteer';

import {setupUIProject, teardownUIProject} from '../utils/cli';
import {
answerPrompt,
getProjectPath,
isGenericYesNoPrompt,
setupUIProject,
teardownUIProject,
} from '../utils/cli';
import {getNewBrowser} from '../utils/browser';
import {isSearchRequest} from '../utils/platform';
import {EOL} from 'os';
import stripAnsi from 'strip-ansi';

describe('ui', () => {
describe('create:angular', () => {
Expand All @@ -19,16 +27,59 @@ describe('ui', () => {
let interceptedRequests: HTTPRequest[] = [];
let page: Page;

// TODO: Refactor.
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
const openNewPage = async () => {
const newPage = await browser.newPage();
if (page) {
await page.close();
}
return newPage;
};

beforeAll(async () => {
browser = await getNewBrowser();
await setupUIProject('ui:create:angular', projectName, cliProcesses, {
flags: ['--defaults'],
timeout: 40e3,
const buildProcess = await setupUIProject(
'ui:create:angular',
projectName,
{
flags: ['--defaults'],
}
);
buildProcess.stdout.on('data', async (data) => {
process.stdout.write(data.toString());
if (isGenericYesNoPrompt(data.toString())) {
await answerPrompt(`y${EOL}`, buildProcess);
}
});
buildProcess.stderr.on('data', async (data) => {
process.stdout.write(data.toString());
});
process.stdout.write('almost ready');
await new Promise<void>((resolve) => {
buildProcess.stdout.on('close', async () => {
resolve();
});
});
process.stdout.write('ready!');

const startServerProcess = spawn('npm', ['run', 'start'], {
cwd: getProjectPath(projectName),
detached: true,
});
cliProcesses.push(startServerProcess);

await new Promise<void>((resolve) => {
startServerProcess.stdout.on('data', async (data) => {
process.stdout.write(data.toString());
if (/Compiled successfully/.test(stripAnsi(data.toString()))) {
resolve();
}
});
});
}, 3e6);

beforeEach(async () => {
page = await browser.newPage();
page = await openNewPage();

page.on('request', (request: HTTPRequest) => {
interceptedRequests.push(request);
Expand All @@ -51,12 +102,16 @@ describe('ui', () => {
});

expect(await page.$('app-search-page')).not.toBeNull();
});
}, 300e3);

it('should retrieve the search token on the page load', async () => {
const tokenResponseListener = page.waitForResponse(tokenProxyEndpoint);

page.goto(searchPageEndpoint);
const tokenResponse = await page.waitForResponse(tokenProxyEndpoint);
expect(JSON.parse(await tokenResponse.text())).toMatchObject({

expect(
JSON.parse(await (await tokenResponseListener).text())
).toMatchObject({
token: expect.stringMatching(/^eyJhb.+/),
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-e2e/__tests__/react.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {getNewBrowser} from '../utils/browser';
import {isSearchRequest} from '../utils/platform';

describe('ui', () => {
describe('create:react', () => {
describe.skip('create:react', () => {
let browser: Browser;
const cliProcesses: ChildProcessWithoutNullStreams[] = [];
// TODO: CDX-90: Assign a dynamic port for the search token server on all ui projects
Expand All @@ -21,9 +21,9 @@ describe('ui', () => {

beforeAll(async () => {
browser = await getNewBrowser();
await setupUIProject('ui:create:react', projectName, cliProcesses, {
timeout: 30e3,
});
// await setupUIProject('ui:create:react', projectName, cliProcesses, {
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
// timeout: 30e3,
// });
}, 3e6);

beforeEach(async () => {
Expand Down
63 changes: 58 additions & 5 deletions packages/cli-e2e/__tests__/vue.specs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import retry from 'async-retry';

import type {ChildProcessWithoutNullStreams} from 'child_process';
import {mkdirSync, writeFileSync} from 'fs';
import {join} from 'path';
import {ChildProcessWithoutNullStreams, spawn} from 'child_process';
import type {HTTPRequest, Browser, Page} from 'puppeteer';

import {setupUIProject, teardownUIProject} from '../utils/cli';
import {
answerPrompt,
getProjectPath,
isGenericYesNoPrompt,
setupUIProject,
teardownUIProject,
} from '../utils/cli';
import {captureScreenshots, getNewBrowser} from '../utils/browser';
import {isSearchRequest} from '../utils/platform';
import stripAnsi from 'strip-ansi';
import {EOL} from 'os';

describe('ui', () => {
describe('create:vue', () => {
Expand All @@ -29,8 +38,52 @@ describe('ui', () => {

beforeAll(async () => {
browser = await getNewBrowser();
await setupUIProject('ui:create:vue', projectName, cliProcesses);
}, 240e3);
const projectPath = getProjectPath(projectName);
mkdirSync(projectPath, {recursive: true});
writeFileSync(
join(projectPath, '.yarnrc'),
'registry "http://verdaccio:4873"'
);
const buildProcess = setupUIProject('ui:create:vue', projectName);
cliProcesses.push(buildProcess);

buildProcess.stdout.on('data', async (data) => {
if (
/Pick an action: \(Use arrow keys\)/.test(stripAnsi(data.toString()))
) {
await answerPrompt('\u001b[B', buildProcess);
return;
}
if (/❯ Merge/.test(stripAnsi(data.toString()))) {
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
await answerPrompt(EOL, buildProcess);
return;
}
if (isGenericYesNoPrompt(data.toString())) {
await answerPrompt(`y${EOL}`, buildProcess);
return;
}
});

await new Promise<void>((resolve) => {
buildProcess.stdout.on('close', async () => {
resolve();
});
});

const startServerProcess = spawn('npm', ['run', 'start'], {
cwd: projectPath,
detached: true,
});

cliProcesses.push(startServerProcess);
await new Promise<void>((resolve) => {
startServerProcess.stdout.on('data', async (data) => {
if (stripAnsi(data.toString()).indexOf('App running at:') !== -1) {
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
resolve();
}
});
});
}, 420e3);

beforeEach(async () => {
page = await openNewPage();
Expand Down
84 changes: 84 additions & 0 deletions packages/cli-e2e/docker/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# This is the config file used for the docker images.
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
# It allows all users to do anything, so don't use it on production systems.
#
# Do not configure host and port under `listen` in this file
# as it will be ignored when using docker.
# see https://verdaccio.org/docs/en/docker#docker-and-custom-port-configuration
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

web:
# WebUI is enabled as default, if you want disable it, just uncomment this line
enable: false
title: Verdaccio
# comment out to disable gravatar support
# gravatar: false
# by default packages are ordercer ascendant (asc|desc)
# sort_packages: asc
# darkMode: true

# translate your registry, api i18n not available yet
# i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
# web: en-US

auth:
htpasswd:
file: /verdaccio/storage/htpasswd
# Maximum amount of users allowed to register, defaults to "+infinity".
# You can set this to -1 to disable registration.
# max_users: 1000

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/

packages:
"@coveo/@(angular|vue-cli-plugin-typescript|cra-template)":
# scoped packages
access: $all
publish: $all
unpublish: $all

"**":
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all

# allow all known users to publish/publish packages
# (anyone can register by default, remember?)
publish: $all
unpublish: $all

# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs

middlewares:
audit:
enabled: true

# log settings
logs:
- { type: stdout, format: pretty, level: http }
#- {type: file, path: verdaccio.log, level: info}
#experiments:
# # support for npm token command
# token: false
# # support for the new v1 search endpoint, functional by incomplete read more on ticket 1732
# search: false

# This affect the web and api (not developed yet)
#i18n:
#web: en-US
34 changes: 34 additions & 0 deletions packages/cli-e2e/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.9"

services:
runner:
image: "coveo-cli-e2e-image"
container_name: "coveo-cli-e2e-container"
cap_add:
- "IPC_LOCK"
- "SYS_ADMIN"
env_file: "../.env"
privileged: true
ports:
- "9229:9229"
volumes:
- ../../..:/home/notGroot/cli
networks:
- node-network
command: "/bin/bash"
tty: true
stdin_open: true
verdaccio:
image: verdaccio/verdaccio
container_name: "verdaccio"
networks:
- node-network
environment:
- VERDACCIO_PORT=4873
ports:
- "4873:4873"
volumes:
- "./config:/verdaccio/conf"
networks:
node-network:
driver: bridge
Loading