diff --git a/.eslintignore b/.eslintignore index e5047805..8b1421e4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ third_party/* utils/doclint/check_public_api/test/ -node6/* \ No newline at end of file +node6/* +node6-test/* \ No newline at end of file diff --git a/.gitignore b/.gitignore index deac790f..38cb0363 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ .vscode package-lock.json /node6 +/node6-test diff --git a/.npmignore b/.npmignore index ea37a1d0..801ec108 100644 --- a/.npmignore +++ b/.npmignore @@ -11,3 +11,4 @@ node_modules *.pyc .vscode package-lock.json +/node6-test diff --git a/.travis.yml b/.travis.yml index bbf8e4c5..4bb542fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,8 @@ install: script: - 'if [ "$NODE7" = "true" ]; then yarn run lint; fi' - 'if [ "$NODE7" = "true" ]; then yarn run coverage; fi' - - 'if [ "$NODE6" = "true" ]; then yarn run node6; fi' - - 'if [ "$NODE6" = "true" ]; then yarn run test-node6; fi' - - 'if [ "$NODE6" = "true" ]; then yarn run node6-sanity; fi' + - 'if [ "$NODE6" = "true" ]; then yarn run test-node6-transformer; fi' + - 'if [ "$NODE6" = "true" ]; then yarn run unit-node6; fi' jobs: include: - node_js: "7" diff --git a/package.json b/package.json index 93b64494..296c060b 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,14 @@ "unit": "jasmine test/test.js", "debug-unit": "DEBUG_TEST=true node --inspect-brk ./node_modules/.bin/jasmine test/test.js", "test-doclint": "jasmine utils/doclint/check_public_api/test/test.js && jasmine utils/doclint/preprocessor/test.js", - "test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-node6", + "test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-node6-transformer", "install": "node install.js", "lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .) && npm run doc", "doc": "node utils/doclint/cli.js", "coverage": "COVERAGE=true npm run unit", - "node6": "node utils/node6-transform/index.js", - "test-node6": "jasmine utils/node6-transform/test/test.js", - "build": "npm run node6", - "node6-sanity": "jasmine test/sanity.js" + "test-node6-transformer": "jasmine utils/node6-transform/test/test.js", + "build": "node utils/node6-transform/index.js", + "unit-node6": "jasmine node6-test/test.js" }, "author": "The Chromium Authors", "license": "SEE LICENSE IN LICENSE", diff --git a/test/sanity.js b/test/sanity.js deleted file mode 100644 index 45fe76cf..00000000 --- a/test/sanity.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2017 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -console.log(process.version); - -describe('Puppeteer Sanity', function() { - it('should not be insane', function(done) { - const puppeteer = require('..'); - puppeteer.launch().then(browser => { - browser.newPage().then(page => { - page.goto('data:text/html,hello').then(() => { - page.evaluate(() => document.body.textContent).then(content => { - expect(content).toBe('hello'); - done(); - }); - }); - }); - }); - }); -}); diff --git a/test/test.js b/test/test.js index 454138d5..02c892cb 100644 --- a/test/test.js +++ b/test/test.js @@ -20,6 +20,7 @@ const path = require('path'); const helper = require('../lib/helper'); if (process.env.COVERAGE) helper.recordPublicAPICoverage(); +console.log('Testing on Node', process.version); const puppeteer = require('..'); const SimpleServer = require('./server/SimpleServer'); const GoldenUtils = require('./golden-utils'); diff --git a/utils/node6-transform/TransformAsyncFunctions.js b/utils/node6-transform/TransformAsyncFunctions.js index 69682637..59319a62 100644 --- a/utils/node6-transform/TransformAsyncFunctions.js +++ b/utils/node6-transform/TransformAsyncFunctions.js @@ -49,6 +49,7 @@ const asyncToGenerator = fn => { /** * @param {string} text + * @return {string} */ function transformAsyncFunctions(text) { const edits = []; diff --git a/utils/node6-transform/index.js b/utils/node6-transform/index.js index f7e864a7..319c457f 100644 --- a/utils/node6-transform/index.js +++ b/utils/node6-transform/index.js @@ -19,18 +19,25 @@ const path = require('path'); const removeRecursive = require('rimraf').sync; const transformAsyncFunctions = require('./TransformAsyncFunctions'); -const dirPath = path.join(__dirname, '..', '..', 'lib'); -const outPath = path.join(__dirname, '..', '..', 'node6'); -const fileNames = fs.readdirSync(dirPath); -const filePaths = fileNames.filter(fileName => fileName.endsWith('.js')); +copyFolder(path.join(__dirname, '..', '..', 'lib'), path.join(__dirname, '..', '..', 'node6')); +copyFolder(path.join(__dirname, '..', '..', 'test'), path.join(__dirname, '..', '..', 'node6-test')); -if (fs.existsSync(outPath)) - removeRecursive(outPath); -fs.mkdirSync(outPath); -filePaths.forEach(filePath => { - const content = fs.readFileSync(path.join(dirPath, filePath), 'utf8'); - const output = transformAsyncFunctions(content); - fs.writeFileSync(path.resolve(outPath, filePath), output); -}); +function copyFolder(source, target) { + if (fs.existsSync(target)) + removeRecursive(target); + fs.mkdirSync(target); + fs.readdirSync(source).forEach(file => { + const from = path.join(source, file); + const to = path.join(target, file); + if (fs.lstatSync(from).isDirectory()) { + copyFolder(from, to); + } else { + let text = fs.readFileSync(from); + if (file.endsWith('.js')) + text = transformAsyncFunctions(text.toString()).replace(/require\('\.\.\/lib\//g, `require('../node6/`); + fs.writeFileSync(to, text); + } + }); +}