Skip to content

Commit f8afda4

Browse files
committed
chore(tests): add e2e tests for mobile app
1 parent 26aeafb commit f8afda4

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

tests/e2e/e2e_workflow.spec.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,114 @@ describe('Basic end-to-end Workflow', function () {
484484
throw new Error(msg);
485485
});
486486
});
487+
488+
it('Can create new project using `ng new test-mobile --mobile`', function () {
489+
this.timeout(4200000);
490+
491+
return ng(['new', 'test-mobile', '--mobile', '--link-cli=true']).then(function () {
492+
expect(existsSync(path.join(root, 'test-project')));
493+
});
494+
});
495+
496+
it('Can change current working directory to `test-mobile`', function () {
497+
process.chdir(path.join(root, 'test-mobile'));
498+
expect(path.basename(process.cwd())).to.equal('test-mobile');
499+
});
500+
501+
it('Has mobile-only files', function () {
502+
expect(existsSync(path.join(process.cwd(), 'app', 'main-app-shell.ts'))).to.be.equal(true);
503+
expect(existsSync(path.join(process.cwd(), 'app', 'manifest.webapp'))).to.be.equal(true);
504+
});
505+
506+
it('Supports production builds via `ng build -prod`', function() {
507+
this.timeout(420000);
508+
509+
sh.exec(`${ngBin} build -prod`);
510+
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
511+
const indexHtml = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8');
512+
// Check for cache busting hash script src
513+
expect(indexHtml).to.match(/main\.[0-9a-f]{20}\.bundle\.js/);
514+
expect(indexHtml).to.match(/sw-install\.[0-9a-f]{20}\.bundle\.js/);
515+
// Also does not create new things in GIT.
516+
expect(sh.exec('git status --porcelain').output).to.be.equal(undefined);
517+
});
518+
519+
it('Can run `ng build` in created project', function () {
520+
this.timeout(420000);
521+
522+
return ng(['build'])
523+
.catch(() => {
524+
throw new Error('Build failed.');
525+
})
526+
.then(function () {
527+
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
528+
// Check the index.html to have no handlebar tokens in it.
529+
const indexHtml = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8');
530+
expect(indexHtml).to.include('main.bundle.js');
531+
})
532+
.then(function () {
533+
// Also does not create new things in GIT.
534+
expect(sh.exec('git status --porcelain').output).to.be.equal(undefined);
535+
});
536+
});
537+
538+
it('lints', () => {
539+
this.timeout(420000);
540+
541+
return ng(['lint']).then(() => {
542+
})
543+
.catch(err => {
544+
throw new Error('Linting failed: ' + err);
545+
});
546+
});
547+
548+
it('Perform `ng test` after initial build', function () {
549+
this.timeout(420000);
550+
551+
return ng(testArgs).then(function (result) {
552+
const exitCode = typeof result === 'object' ? result.exitCode : result;
553+
expect(exitCode).to.be.equal(0);
554+
});
555+
});
556+
557+
it('Serve and run e2e tests after initial build', function () {
558+
this.timeout(240000);
559+
560+
var ngServePid;
561+
562+
function executor(resolve, reject) {
563+
var serveProcess = child_process.exec(`${ngBin} serve`, {maxBuffer: 500*1024});
564+
var startedProtractor = false;
565+
ngServePid = serveProcess.pid;
566+
567+
serveProcess.stdout.on('data', (data) => {
568+
if (/webpack: bundle is now VALID/.test(data.toString('utf-8')) && !startedProtractor) {
569+
startedProtractor = true;
570+
child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => {
571+
if (error !== null) {
572+
reject(stderr)
573+
} else {
574+
resolve();
575+
}
576+
});
577+
}
578+
});
579+
580+
serveProcess.stderr.on('data', (data) => {
581+
reject(data);
582+
});
583+
serveProcess.on('close', (code) => {
584+
code === 0 ? resolve() : reject('ng serve command closed with error')
585+
});
586+
}
587+
588+
return new Promise(executor)
589+
.then(() => {
590+
if (ngServePid) treeKill(ngServePid);
591+
})
592+
.catch((msg) => {
593+
if (ngServePid) treeKill(ngServePid);
594+
throw new Error(msg);
595+
});
596+
});
487597
});

0 commit comments

Comments
 (0)