Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amphtml-validator

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amphtml-validator - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

52

index_test.js

@@ -71,4 +71,4 @@ #!/usr/bin/env node

.then(function(instance) {
var validationResult = instance.validateString('');
expect(validationResult.status).toBe('FAIL');
var validationResult = instance.validateString(mini);
expect(validationResult.status).toBe('PASS');
done();

@@ -82,2 +82,18 @@ })

it('accepts the minimum valid AMP4ADS file', function(done) {
// Note: This will use the validator that was built with build.py.
var mini = fs.readFileSync(
'../testdata/amp4ads_feature_tests/min_valid_amp4ads.html', 'utf-8');
ampValidator.getInstance(/*validatorJs*/ '../dist/validator_minified.js')
.then(function(instance) {
var validationResult = instance.validateString(mini, 'AMP4ADS');
expect(validationResult.status).toBe('PASS');
done();
})
.catch(function(error) {
fail(error);
done();
});
});
it('rejects a specific file that is known to have errors', function(done) {

@@ -123,4 +139,4 @@ // Note: This will use the validator that was built with build.py.

expect(error.message)
.toBe(
'Could not instantiate validator.js - Unexpected token ILLEGAL');
.toMatch(
/^Could not instantiate validator\.js -.*[Uu]nexpected token/);
done();

@@ -154,3 +170,2 @@ });

it('emits json if --format=json is specified on command line', function(done) {

@@ -185,4 +200,31 @@ execFile(

it('supports AMP4ADS with --html_format command line option', function(done) {
var severalErrorsOut =
fs.readFileSync(
'../testdata/amp4ads_feature_tests/style-amp-custom.out',
'utf-8')
.split('\n')
.splice(1) // trim 1st line
.join('\n')
.replace(/ \[[A-Z_]+\]/g, ''); // trim error categories
execFile(
process.execPath,
[
'../nodejs/index.js', '--format=text', '--html_format=AMP4ADS',
'--validator_js=../dist/validator_minified.js',
'amp4ads_feature_tests/style-amp-custom.html',
'amp4ads_feature_tests/min_valid_amp4ads.html'
],
{'cwd': '../testdata'}, // Run inside the testdata dir to match paths.
function(error, stdout, stderr) {
expect(error).toBeDefined(); // At least one file had errors.
expect(stderr).toBe(severalErrorsOut);
expect(stdout).toBe(
'amp4ads_feature_tests/min_valid_amp4ads.html: PASS\n');
done();
});
}, 5000);
jasmine.onComplete(function(passed) { process.exit(passed ? 0 : 1); });
jasmine.execute();

30

index.js

@@ -80,4 +80,8 @@ #!/usr/bin/env node

readable.setEncoding('utf8');
readable.on('data', function(chunk) { chunks.push(chunk); });
readable.on('end', function() { resolve(chunks.join('')); });
readable.on('data', function(chunk) {
chunks.push(chunk);
});
readable.on('end', function() {
resolve(chunks.join(''));
});
readable.on('error', function(error) {

@@ -249,9 +253,12 @@ reject(new Error('Could not read from ' + name + ' - ' + error.message));

/**
* Validates the provided inputString; the htmlFormat can be 'AMP' or
* 'AMP4ADS'; it defaults to 'AMP' if not specified.
* @param {!string} inputString
* @param {string=} htmlFormat
* @returns {!ValidationResult}
* @export
*/
Validator.prototype.validateString =
function(inputString) {
var internalResult = this.sandbox.amp.validator.validateString(inputString);
Validator.prototype.validateString = function(inputString, htmlFormat) {
var internalResult =
this.sandbox.amp.validator.validateString(inputString, htmlFormat);
var result = new ValidationResult();

@@ -322,4 +329,3 @@ result.status = internalResult.status;

if (validationResult.status === 'PASS') {
console.log(
filename + ': ' + (color ? colors.green('PASS') : 'PASS'));
console.log(filename + ': ' + (color ? colors.green('PASS') : 'PASS'));
}

@@ -362,2 +368,8 @@ for (var ii = 0; ii < validationResult.errors.length; ii++) {

.option(
'--html_format <AMP|AMP4ADS>', 'The input format to be validated.\n' +
' AMP by default. AMP4ADS is a format for ads creatives that is\n' +
' still in draft; this requires specifying \n' +
' https://cdn.ampproject.org/v0/validator-canary.js as validator.js.',
'AMP')
.option(
'--format <color|text|json>', 'How to format the output.\n' +

@@ -393,4 +405,4 @@ ' "color" displays errors/warnings/success in\n' +

for (var ii = 0; ii < resolvedInputs.length; ii++) {
var validationResult =
validator.validateString(resolvedInputs[ii]);
var validationResult = validator.validateString(
resolvedInputs[ii], program.html_format);
if (program.format === 'json') {

@@ -397,0 +409,0 @@ jsonOut[program.args[ii]] = validationResult;

{
"name": "amphtml-validator",
"version": "1.0.10",
"version": "1.0.11",
"description": "Validator for AMP HTML (www.ampproject.org)",

@@ -5,0 +5,0 @@ "engines": {

@@ -1,40 +0,13 @@

# amphtml-validator Node.js package (Beta!)
# amphtml-validator Node.js Package
## Using the command-line tool (Beta!)
This package is published and available at
https://www.npmjs.com/package/amphtml-validator.
To install this as a command line tool, type `npm install -g amphtml-validator`.
## Command Line Tool
Now let's validate a real AMP HTML page.
```
$ amphtml-validator https://www.ampproject.org/
https://www.ampproject.org/: PASS
```
The `amphtml-validator` command line tool is documented here:
https://www.ampproject.org/docs/guides/validate.html#command-line-tool
How about an empty file? Turns out an empty file is not valid AMP.
```
$ echo > empty.html
$ amphtml-validator empty.html
empty.html:1:0 The mandatory tag 'html doctype' is missing or incorrect.
empty.html:1:0 The mandatory tag 'html ⚡ for top-level html' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec.html#required-markup)
empty.html:1:0 The mandatory tag 'head' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec.html#required-markup)
...
```
## Node.js API (Beta!)
OK, let's try a better starting point. Let's verify that this document is
valid AMP.
```
$ amphtml-validator https://raw.githubusercontent.com/ampproject/amphtml/master/validator/testdata/feature_tests/minimum_valid_amp.html
https://raw.githubusercontent.com/ampproject/amphtml/master/validator/testdata/feature_tests/minimum_valid_amp.html: PASS
```
Great, we download it and edit it. You may use `vim` if you don't like Emacs.
```
$ wget --output-document=hello-amp.html https://raw.githubusercontent.com/ampproject/amphtml/master/validator/testdata/feature_tests/minimum_valid_amp.html
$ amphtml-validator hello-amp.html
hello-amp.html: PASS
$ emacs hello-amp.html
```
## Using the Node.js API (Beta!)
This API is new and still experimental, feedback is especially welcome.

@@ -77,1 +50,4 @@

* Fixed [#4246: amphtml-validator CLI fails on Mac OS X](https://github.com/ampproject/amphtml/issues/4246).
### 1.0.11
* Added support for AMP4ADS (via --html_format command line flag) and
argument for validateString function in the API.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc