test('compiles ES2017 to ES5', async () => { const result = jsTransform('async function test() { await 0; }', {compile: 'es5'}); assert.include(result, '_asyncToGenerator'); assert.notInclude(result, 'async function test'); assert.include(result, 'regeneratorRuntime'); });
test('adds prefetch links for transitive deps of unbundled', async () => { const project = new PolymerProject({ root: 'test-fixtures/bundle-project/', entrypoint: 'index.html', }); const files = await emittedFiles( mergeStream(project.sources(), project.dependencies()) .pipe(project.addPrefetchLinks()), project.config.root); const html = files.get('index.html').contents.toString(); // No prefetch links needed for direct dependency. assert.notInclude( html, '<link rel="prefetch" href="/simple-import.html">'); // Prefetch added for the transitive dependencies of `index.html`, // which are all direct dependencies of `simple-import.html`. assert.include(html, '<link rel="prefetch" href="/simple-script.js">'); assert.include(html, '<link rel="prefetch" href="/simple-style.css">'); assert.include( html, '<link rel="prefetch" href="/simple-import-2.html">'); });
test('bundler deals with posix platform separators on win32', async () => { const posixSepPaths = new FileTransform((stream, file) => { if (path.sep === '\\') { file.path = file.path.replace(/\\/g, '/'); } stream.push(file); }); await setupTest( { root: path.resolve('test-fixtures/bundle-project'), entrypoint: 'index.html' }, {}, posixSepPaths); const bundledHtml = getFileOrDie('index.html'); // In setupTest, we use a transform stream that forces the file paths to // be in the posix form (this only changes/matters for win32) // and it verifies that bundler can process files that may be merged in // or have otherwise have paths in posix separator form. assert.include(bundledHtml, '<title>Sample Build</title>', 'index.html'); assert.include( bundledHtml, '<dom-module id="my-element">', 'simple-import.html'); assert.include( bundledHtml, '<dom-module id="my-element-2">', 'simple-import-2.html'); assert.include(bundledHtml, '.simply-red', 'simple-style.css'); });
.run(err => { if (err) throw err; let pkg = JSON.parse(readFile(this.cwd, 'my-app/package.json')); assert.propertyVal(pkg, 'name', 'my-app'); assert.propertyVal(pkg, 'version', '0.1.0'); assert.propertyVal(pkg, 'description', 'My new app!'); assert.propertyVal(pkg, 'license', 'MIT'); assert.deepProperty(pkg, 'dependencies.neon-cli'); let cargo = TOML.parse(readFile(this.cwd, 'my-app/native/Cargo.toml')); assert.deepPropertyVal(cargo, 'package.name', 'my-app'); assert.deepPropertyVal(cargo, 'package.version', '0.1.0'); assert.deepPropertyVal(cargo, 'package.license', 'MIT'); assert.deepPropertyVal(cargo, 'lib.name', 'my_app'); assert.deepProperty(cargo, 'dependencies.neon'); let indexjs = readFile(this.cwd, 'my-app/lib/index.js'); assert.include(indexjs, `require('../native')`); let librs = readFile(this.cwd, 'my-app/native/src/lib.rs'); assert.include(librs, `extern crate neon;`); done(); });
it("mentions the root cause if a config file extends from an invalid file", async () => { const result = await execRunnerWithOutput({config: "test/config/tslint-extends-invalid.json", files: ["src/test.ts"]}); assert.equal(result.status, Status.FatalError, "process should exit with error"); assert.include(result.stderr, "Failed to load", "stderr should contain notification about failing to load json config"); assert.include(result.stderr, "tslint-invalid.json", "stderr should mention the problem file"); assert.strictEqual(result.stdout, "", "shouldn't contain any output in stdout"); });
test('displays command help when called with the --help flag', async () => { const cli = new PolymerCli(['build', '--help']); const output = await interceptOutput(async () => { await cli.run(); }); assert.include(output, 'polymer build'); assert.include(output, 'Command Options'); assert.include(output, '--bundle'); });
it('should add a graphql error to the message', () => { const graphQLErrors = [ new Error('this is an error message') ]; const apolloError = new ApolloError({ graphQLErrors, }); assert.include(apolloError.message, 'GraphQL error: '); assert.include(apolloError.message, 'this is an error message'); assert.equal(apolloError.message.split('\n').length, 1); });
test('displays command help when called with the -h flag', async () => { const cli = new PolymerCli(['init', '-h']); const output = await interceptOutput(async () => { await cli.run(); }); assert.include(output, 'polymer init'); assert.include(output, 'Command Options'); assert.include(output, '--name'); });
it('should return some proper html', function () { const html = ServerRenderer.render(store.createDefault({log: false})); assert.isString(html, "The rendered HTML needs to be a string"); assert.include(html, '<div', 'rendered HTML contains at least an open div'); assert.include(html, '</div>', 'rendered HTML contains at least an closed div'); // TODO: Make assumptions about the state in store.getState(); });
it('should add a network error to the message', () => { const networkError = new Error('this is an error message'); const apolloError = new ApolloError({ networkError, }); assert.include(apolloError.message, 'Network error: '); assert.include(apolloError.message, 'this is an error message'); assert.equal(apolloError.message.split('\n').length, 1); });