Skip to content

Commit

Permalink
add util to list native support data
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Dec 1, 2023
1 parent 88b6cfe commit b1baa88
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ web-tests-migrate-makefile: $(wildcard web-tests-migrate-makefile/*) $(wildcard
web-tests-collect-ua-strings: $(wildcard web-tests-collect-ua-strings/*) $(wildcard browserstack/*) $(wildcard browserua/*) $(wildcard feature/*) $(wildcard priority/*) $(wildcard result/*) $(wildcard store/*)
go install ./web-tests-collect-ua-strings/...

web-tests-native-support-data: $(wildcard web-tests-native-support-data/*) $(wildcard browserstack/*) $(wildcard browserua/*) $(wildcard feature/*) $(wildcard priority/*) $(wildcard result/*) $(wildcard store/*)
go install ./web-tests-native-support-data/...

web-tests-collect-polyfillio-hashes: $(wildcard web-tests-collect-polyfillio-hashes/*) $(wildcard browserstack/*) $(wildcard browserua/*) $(wildcard feature/*) $(wildcard priority/*) $(wildcard result/*) $(wildcard store/*)
go install ./web-tests-collect-polyfillio-hashes/...

web-tests-passes: $(wildcard web-tests-passes/*) $(wildcard browserstack/*) $(wildcard browserua/*) $(wildcard feature/*) $(wildcard priority/*) $(wildcard result/*) $(wildcard store/*)
go install ./web-tests-passes/...

all: web-tests-browserstack web-tests-browserstack-single web-tests-build-mapping web-tests-build-test web-tests-new-test web-tests-pages web-tests-migrate-meta web-tests-migrate-makefile web-tests-collect-ua-strings web-tests-collect-polyfillio-hashes web-tests-passes
all: web-tests-browserstack web-tests-browserstack-single web-tests-build-mapping web-tests-build-test web-tests-new-test web-tests-pages web-tests-migrate-meta web-tests-migrate-makefile web-tests-collect-ua-strings web-tests-collect-polyfillio-hashes web-tests-passes web-tests-native-support-data

.PHONY: all web-tests-browserstack web-tests-browserstack-single web-tests-build-mapping web-tests-build-test web-tests-new-test web-tests-pages web-tests-migrate-meta web-tests-migrate-makefile web-tests-collect-ua-strings web-tests-collect-polyfillio-hashes web-tests-passes
.PHONY: all web-tests-browserstack web-tests-browserstack-single web-tests-build-mapping web-tests-build-test web-tests-new-test web-tests-pages web-tests-migrate-meta web-tests-migrate-makefile web-tests-collect-ua-strings web-tests-collect-polyfillio-hashes web-tests-passes web-tests-native-support-data
122 changes: 122 additions & 0 deletions scripts/web-tests-native-support-data/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package main

import (
"context"
"flag"
"fmt"
"log"
"sort"

version "github.com/hashicorp/go-version"
"github.com/mrhenry/web-tests/scripts/feature"
"github.com/mrhenry/web-tests/scripts/result"
"github.com/mrhenry/web-tests/scripts/store"
)

func main() {
var featureArg string

flag.StringVar(&featureArg, "feature", "", "Feature to construct mdn compat data for")

flag.Parse()

db, err := store.NewSqliteDatabase("./web-tests.db", false)
if err != nil {
log.Fatal(err)
}

featureInMapping := feature.FeatureInMapping{}
featureInMapping.ID = featureArg

feature, err := store.SelectFeature(context.Background(), db, featureInMapping)
if err != nil {
log.Fatal(err)
}

safari := []result.Result{}
chrome := []result.Result{}
firefox := []result.Result{}
ios := []result.Result{}

allResultsForFeature, err := store.SelectResultsForFeature(context.Background(), db, feature)
if err != nil {
log.Fatal(err)
}

for _, r := range allResultsForFeature {
if r.Test != "pure" {
continue
}

if r.Score == -1 {
continue
}

if r.OS == "ios" {
r.Browser = "safari_ios"
}

switch r.Browser {
case "safari":
safari = append(safari, r)
case "chrome":
chrome = append(chrome, r)
case "firefox":
firefox = append(firefox, r)
case "safari_ios":
ios = append(ios, r)
}
}

sort.Sort(Results(safari))
sort.Sort(Results(chrome))
sort.Sort(Results(firefox))
sort.Sort(Results(ios))

for i := 1; i < len(safari); i++ {
logResults(safari[i-1], safari[i])
}

for i := 1; i < len(chrome); i++ {
logResults(chrome[i-1], chrome[i])
}

for i := 1; i < len(firefox); i++ {
logResults(firefox[i-1], firefox[i])
}

for i := 1; i < len(ios); i++ {
logResults(ios[i-1], ios[i])
}
}

type Results []result.Result

func (x Results) Len() int {
return len(x)
}

func (x Results) Less(i int, j int) bool {
v1, _ := version.NewVersion(x[i].BrowserVersion)
v2, _ := version.NewVersion(x[j].BrowserVersion)

if v1 != nil && v2 != nil {
return v1.GreaterThan(v2)
}

panic("could not compare versions")
}

func (x Results) Swap(i int, j int) {
x[i], x[j] = x[j], x[i]
}

func logResults(a result.Result, b result.Result) {
if a.Score == b.Score {
return
}

fmt.Printf("%s %s: %3f\n", a.Browser, a.BrowserVersion, a.Score)
fmt.Printf("%s %s: %3f\n", b.Browser, b.BrowserVersion, b.Score)
fmt.Println("-----------------------")
}

0 comments on commit b1baa88

Please sign in to comment.