-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a unique identifier to AMP sw as a comment (#33)
* adding a unique identifier to the service worker body * adding a unique identifier to the AMP_SW * fixing version number problem * fixing test as per comments
- Loading branch information
1 parent
a62de34
commit 3aded4e
Showing
3 changed files
with
119 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import test from 'ava'; | ||
import * as fs from 'fs'; | ||
import { promisify } from 'util'; | ||
import { resolve, join } from 'path'; | ||
import webpack from 'webpack'; | ||
import webpackConfig from '../../webpack.config'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
const copyFile = promisify(fs.copyFile); | ||
const deleteFile = promisify(fs.unlink); | ||
|
||
const newPackageFile = resolve(join('.', '.test-package.json')); | ||
const version = `${Date.now()}.0.0`; | ||
|
||
test.before(async () => { | ||
await copyFile('./package.json', newPackageFile); | ||
const packageData = await readFile(newPackageFile, { | ||
encoding: 'utf-8', | ||
}); | ||
const packageJSON = JSON.parse(packageData); | ||
packageJSON.version = version; | ||
await writeFile(newPackageFile, JSON.stringify(packageJSON)); | ||
|
||
const compiler = webpack(webpackConfig({ packageFile: newPackageFile })); | ||
return new Promise((res, rej) => { | ||
compiler.run((err, stats) => { | ||
if (err || (stats && stats.hasErrors())) { | ||
rej(); | ||
} | ||
res(stats); | ||
}); | ||
}); | ||
}); | ||
|
||
test.after(async () => { | ||
await deleteFile(newPackageFile); | ||
}); | ||
|
||
test('should have the package version for the bundle', async t => { | ||
const entryBundlePath = resolve(__dirname, '../../dist/amp-sw.js'); | ||
const entryBundleContent = await readFile(entryBundlePath, 'utf-8'); | ||
t.assert(entryBundleContent.startsWith(`/*! AMP_SW_v${version} */`)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters