Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Feb 26, 2020
1 parent 3017b5a commit 49d001b
Show file tree
Hide file tree
Showing 164 changed files with 28,135 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type DeepPartial<T> = {
// interface this library uses internally
export interface SnowpackConfig {
source: 'local' | 'pika';
dependencies?: {[packageName: string]: string};
webDependencies?: string[];
dedupe?: string[];
namedExports?: {[filepath: string]: string[]};
Expand Down Expand Up @@ -70,7 +69,6 @@ const configSchema = {
type: 'object',
properties: {
source: {type: 'string'},
dependencies: {type: 'object'},
webDependencies: {type: 'array', items: {type: 'string'}},
dedupe: {
type: 'array',
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ export async function cli(args: string[]) {

const {
installOptions: {clean, dest, exclude, include},
dependencies,
webDependencies,
source,
} = config;
Expand All @@ -512,7 +511,6 @@ export async function cli(args: string[]) {
const implicitDependencies = [
...Object.keys(pkgManifest.peerDependencies || {}),
...Object.keys(pkgManifest.dependencies || {}),
...Object.keys(dependencies || {}),
];
const hasBrowserlistConfig =
!!pkgManifest.browserslist ||
Expand Down
2 changes: 0 additions & 2 deletions src/resolve-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ export async function resolveTargetsFromRemoteCDN(
pkgManifest: any,
config: SnowpackConfig,
) {
const {dependencies} = config;
const downloadQueue = new PQueue({concurrency: 16});
const newLockfile: ImportMap = {imports: {}};

const allInstallSpecifiers = new Set(installTargets.map(dep => dep.specifier));
for (const installSpecifier of allInstallSpecifiers) {
const installSemver: string =
(dependencies || {})[installSpecifier] ||
(pkgManifest.dependencies || {})[installSpecifier] ||
(pkgManifest.devDependencies || {})[installSpecifier] ||
(pkgManifest.peerDependencies || {})[installSpecifier] ||
Expand Down
22 changes: 22 additions & 0 deletions test/integration/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ const path = require('path');
const fs = require('fs').promises;
const {readdirSync, readFileSync} = require('fs');
const execa = require('execa');
const rimraf = require('rimraf');
const dircompare = require('dir-compare');

const KEEP_LOCKFILE = [
'source-pika-lockfile', // We explicitly want to test the lockfile in this test
];

const SKIP_FILE_CHECK = [
'config-rollup', // only expected-output.txt is needed for the test, and Windows comparison fails because of backslashes
];
Expand Down Expand Up @@ -36,6 +41,12 @@ for (const testName of readdirSync(__dirname)) {
}

test(testName, async () => {
// Prepare test directory
const testDir = path.join(__dirname, testName);
if (!KEEP_LOCKFILE.includes(testName)) {
rimraf.sync(path.join(testDir, 'snowpack.lock.json'));
}

const {all} = await execa('npm', ['run', `TEST`, `--silent`], {
cwd: path.join(__dirname, testName),
reject: false,
Expand All @@ -48,6 +59,17 @@ for (const testName of readdirSync(__dirname)) {
stripWhitespace(expectedOutput),
);

// Test Lockfile (if one exists)
const expectedLockLoc = path.join(__dirname, testName, 'expected-lock.json');
const expectedLock = await fs
.readFile(expectedLockLoc, {encoding: 'utf8'})
.catch((/* ignore */) => null);
if (expectedLock) {
const actualLockLoc = path.join(__dirname, testName, 'snowpack.lock.json');
const actualLock = await fs.readFile(actualLockLoc, {encoding: 'utf8'});
assert.strictEqual(stripWhitespace(actualLock), stripWhitespace(expectedLock));
}

const expectedWebDependenciesLoc = path.join(__dirname, testName, 'expected-install');
const actualWebDependenciesLoc = path.join(__dirname, testName, 'web_modules');
const expectedWebDependencies = await fs.readdir(expectedWebDependenciesLoc).catch(() => {});
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"async": "./async.js"
}
}
5 changes: 5 additions & 0 deletions test/integration/source-pika-lockfile/expected-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"async": "https://cdn.pika.dev/async@v3.1.0-ENwq8gsjdqg55EqedqGF/minified"
}
}
2 changes: 2 additions & 0 deletions test/integration/source-pika-lockfile/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- snowpack installing...
✔ snowpack installed: async.
11 changes: 11 additions & 0 deletions test/integration/source-pika-lockfile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "Test that the lockfile import URLs & version info are used",
"scripts": {
"TEST": "node ../../../pkg/dist-node/index.bin.js --source pika"
},
"snowpack": {
"webDependencies": [
"async"
]
}
}
5 changes: 5 additions & 0 deletions test/integration/source-pika-lockfile/snowpack.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"async": "https://cdn.pika.dev/async@v3.1.0-ENwq8gsjdqg55EqedqGF/minified"
}
}
Loading

0 comments on commit 49d001b

Please sign in to comment.