Skip to content

Commit

Permalink
Merge pull request #6 from Polymer/gen-tests
Browse files Browse the repository at this point in the history
Add integration tests for some representative Polymer libraries.
  • Loading branch information
aomarks authored Oct 16, 2017
2 parents 19898ab + 18867e2 commit 8157320
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib/
lib
src/test/fixtures
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/mocha": "^2.2.43",
"bower": "^1.8.2",
"chai": "^4.1.2",
"clang-format": "^1.0.55",
"mocha": "^3.5.3",
"rimraf": "^2.6.2",
"source-map-support": "^0.5.0",
"typescript": "^2.5.3",
"watchy": "^0.7.0"
Expand All @@ -31,8 +33,11 @@
"format": "find src -name '*.ts' | xargs clang-format --style=file -i",
"build": "npm run clean && tsc",
"build:watch": "tsc --watch",
"test": "npm run build && mocha",
"test:watch": "watchy -w src -- npm run test"
"test": "npm run test:setup-once && npm run build && mocha",
"test:watch": "watchy -w src -- npm run test",
"test:setup": "scripts/setup-fixtures.sh",
"test:setup-once": "mkdir src/test/fixtures && npm run test:setup || true",
"test:make-goldens": "scripts/make-goldens.js"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions scripts/fixtures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/PolymerElements/paper-button.git v2.0.0 paper-button
https://github.com/PolymerElements/paper-behaviors.git v2.0.1 paper-behaviors
https://github.com/Polymer/polymer.git v2.1.1 polymer
39 changes: 39 additions & 0 deletions scripts/make-goldens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node

/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
* Google as part of the polymer project is also subject to an additional IP
* rights grant found at http://polymer.github.io/PATENTS.txt
*/

/**
* This script should be run from `npm run test:make-goldens`. It runs the
* TypeScript declarations generator across all repos in the
* `test/src/fixtures` directory, and writes the output to
* `test/src/goldens/<fixture>/expected.d.ts`. The results of this script
* *should* be checked in.
*/

const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const {generateDeclarations} = require('../lib/gen-ts');

const fixturesDir = path.join(__dirname, '..', 'src', 'test', 'fixtures');
const goldensDir = path.join(__dirname, '..', 'src', 'test', 'goldens');

rimraf.sync(goldensDir);
fs.mkdirSync(goldensDir);

for (const dir of fs.readdirSync(fixturesDir)) {
generateDeclarations(path.join(fixturesDir, dir)).then((declarations) => {
const outDir = path.join(goldensDir, dir);
fs.mkdirSync(outDir);
fs.writeFileSync(path.join(outDir, 'expected.d.ts'), declarations);
});
}
30 changes: 30 additions & 0 deletions scripts/setup-fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
# This code may only be used under the BSD style license found at
# http://polymer.github.io/LICENSE.txt The complete set of authors may be found
# at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
# be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
# Google as part of the polymer project is also subject to an additional IP
# rights grant found at http://polymer.github.io/PATENTS.txt

# This script should be run from `npm run test:setup`. It reads a list of repos
# from `fixtures.txt`, clones them into the `src/test/fixtures` directory, and
# installs them for testing.
#
# To add a new repo for testing, add it to `fixtures.txt`, run `npm run
# test:setup && npm run test:make-goldens`.

set -e

cd src/test
rm -rf fixtures
mkdir fixtures
cd fixtures

while read -r repo tag dir; do
git clone $repo --branch $tag --single-branch --depth 1 $dir
cd $dir
bower install
cd -
done < ../../../scripts/fixtures.txt
31 changes: 31 additions & 0 deletions src/test/gen-ts_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
* Google as part of the polymer project is also subject to an additional IP
* rights grant found at http://polymer.github.io/PATENTS.txt
*/

import {assert} from 'chai';
import * as fs from 'fs';
import * as path from 'path';

import {generateDeclarations} from '../gen-ts';

const fixtures = path.join(__dirname, '..', '..', 'src', 'test', 'fixtures');
const goldens = path.join(__dirname, '..', '..', 'src', 'test', 'goldens');

suite('generateDeclarations', () => {
for (const fixture of fs.readdirSync(goldens)) {
test(fixture, async () => {
const golden =
fs.readFileSync(path.join(goldens, fixture, 'expected.d.ts'));
const declarations =
await generateDeclarations(path.join(fixtures, fixture));
assert.equal(declarations, golden.toString());
}).timeout(30000); // These tests can take a long time.
}
});
4 changes: 4 additions & 0 deletions src/test/goldens/paper-behaviors/expected.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare namespace Polymer {
type Constructor<T> = new(...args: any[]) => T;

}
4 changes: 4 additions & 0 deletions src/test/goldens/paper-button/expected.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare namespace Polymer {
type Constructor<T> = new(...args: any[]) => T;

}
Loading

0 comments on commit 8157320

Please sign in to comment.